Mos*_*she 16 iphone core-animation subview ios
我想要一个视图在通过添加到堆栈时淡入
[self.view addSubview:someSecondaryViewController.view];
如何设置此调用的动画以使视图淡入(和退出)?
dra*_*ard 29
在动画制作之前将alpha设置为零,然后将alpha动画设为1.
[fadingView setAlpha:0.0];
[containerView addSubview:fadingView];
[UIView beginAnimations:nil context:nil];
[fadingView setAlpha:1.0];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
在删除视图之前,只需将alpha动画设置为零.
顺便说一句,视图层次结构更像是树而不是堆栈.
编辑:
如果在淡出视图时动画结束后没有其他清理,则使用:
[UIView setAnimationDelegate:fadingView];
[UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];
Run Code Online (Sandbox Code Playgroud)
如果您已经设置了didStopSelector,那么请在那里调用removeFromSuperview.
Web*_*eed 21
完成淡出动画后,您还可以使用块从超级视图中删除视图:
[UIView animateWithDuration:0.2
animations:^{viewOut.alpha = 0.0;}
completion:^(BOOL finished){[viewOut removeFromSuperview];}];
Run Code Online (Sandbox Code Playgroud)