iOS 多个对象的淡入淡出动画
我有一个 iOS 应用程序,每次加载视图时,视图中的所有对象都会快速淡入。
在我的代码中,我有一个
- (void)fadeInEverything
函数,在这个函数中,我调用五个不同的函数,每个函数上都有一个 NSTimer 的
[self fadeInLabel];
[NSTimer scheduledTimerWithTimeInterval:0.2
target:self
selector:@selector(fadeInTextField)
userInfo:nil
repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.4
target:self
selector:@selector(fadeInButton)
userInfo:nil
repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.6
target:self
selector:@selector(fadeInTextView)
userInfo:nil
repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.8
target:self
selector:@selector(fadeInFlipsideViewButton)
userInfo:nil
repeats:NO];
函数
- (void)fadeInTextView
{
[resultView setAlpha:0];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[resultView setAlpha:1];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
我的问题是,我们是否有一种方法可以制作一个带有参数(对象)并淡入淡出 它在,所以我不必有五个几乎相同的功能?这将为我节省大量空间和混乱。
I have an iOS app in which every time the view is loaded, all of the objects in the view quickly fade in.
In my code, I have a
- (void)fadeInEverything
function, and within this function, I call five different functions, with an NSTimer on each of them, so that the objects fade in sequentially, like this:
[self fadeInLabel];
[NSTimer scheduledTimerWithTimeInterval:0.2
target:self
selector:@selector(fadeInTextField)
userInfo:nil
repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.4
target:self
selector:@selector(fadeInButton)
userInfo:nil
repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.6
target:self
selector:@selector(fadeInTextView)
userInfo:nil
repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.8
target:self
selector:@selector(fadeInFlipsideViewButton)
userInfo:nil
repeats:NO];
I have a function that looks like this for each object:
- (void)fadeInTextView
{
[resultView setAlpha:0];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[resultView setAlpha:1];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
My question is, would there we a way to make one function that would take a parameter (the object) and fade it in, so I don't have to have five almost identical functions? It would save me a lot of space and clutter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过引用传递对象来完成此操作:
并且调用方法可能如下所示:
You could pass your object by reference to accomplish that:
And the calling method could look like this: