Ric*_*cky 19 animation objective-c uiview
我试图淡化UIView作为我主视图的子视图.我试图淡入的UIView的尺寸为320x55.
我设置了视图和计时器;
secondView.frame = CGRectMake(0, 361, 320, 55);
secondView.alpha = 0.0;
[self.view addSubview:secondView];
[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(fadeView) userInfo:NO repeats:NO];
Run Code Online (Sandbox Code Playgroud)
计时器触发以下代码;
secondView.alpha = 1.0;
CABasicAnimation *fadeInAnimation;
fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeInAnimation.duration = 1.5;
fadeInAnimation.fromValue = [NSNumber numberWithFloat:0.0];
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
[fadeInAnimation setDelegate:self];
[secondView.layer addAnimation:fadeInAnimation forKey:@"animateOpacity"];
Run Code Online (Sandbox Code Playgroud)
我的第二个视图在Interface Builder中连接并响应其他消息但我看不到屏幕上发生的任何事情.
谁能帮助我弄清楚这里发生了什么?
谢谢,瑞奇.
在回复以下建议时:
我在这里有点不确定.最初我把这段代码放进去(因为我看到secondView作为UIView的一个实例?):
[secondView beginAnimations:nil context:NULL];
[secondView setAnimationDuration:0.5];
[secondView setAlpha:1.0];
[secondView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
然后我尝试了你的建议,它没有产生警告或错误,但它仍然没有带来任何表面:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[secondView setAlpha:1.0];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
谢谢!瑞奇.
kub*_*ubi 43
你应该能够做到这一点更简单.你尝试过这样的事吗?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[secondView setAlpha:1.0];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
ste*_*veb 16
在我看来,你遗漏的一件事是你的视图可能已经有1.0的alpha值.在动画调用之前确保alpha为0(或任何你想要的).
我更喜欢使用块动画.它更清洁,更独立.
secondView.alpha = 0.0f;
[UIView animateWithDuration:1.5 animations:^() {
secondView.alpha = 1.0f;
}];
Run Code Online (Sandbox Code Playgroud)
ken*_*ytm 11
如果您坚持使用CoreAnimations,这将无法回答您的问题,但对于iPhoneOS,使用UIView动画的动画块要容易得多.
secondView.alpha = 0.0f;
[UIView beginAnimations:@"fadeInSecondView" context:NULL];
[UIView setAnimationDuration:1.5];
secondView.alpha = 1.0f;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
此外,您可以在延迟时间内调用委托
[self performSelector:@selector(fadeView) withObject:nil afterDelay:0.5];
Run Code Online (Sandbox Code Playgroud)
这里也是一个很好的选择,有很多选项,而且易于使用.
[secondViewController.view setAlpha:0.0];
[UIView animateWithDuration:1.5
delay:0.0
options:UIViewAnimationOptionCurveEaseIn // See other options
animations:^{
[secondViewController.view setAlpha:1.0];
}
completion:^(BOOL finished) {
// Completion Block
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29630 次 |
| 最近记录: |