【发布时间】:2013-05-23 08:04:26
【问题描述】:
我有一个 UIViewController 和一个用于向 UIViewController 添加方法的类别。类中有一个方法:
@implementation UIViewController (AlertAnimationsAndModalViews)
-(void)someAddedMethod
{
UIView *someView;
//do some animation with the view that lasts 3 seconds
//remove the view and return
}
在任何视图控制器中我都可以调用这个方法
[self someAddedMethod];
但是,我只想允许此方法一次运行一个。例如,如果我一个接一个地拨打两个电话
[self someAddedMethod];//call1
[self someAddedMethod];//call2
我希望第二次通话等到第一次通话完成。我知道 UIView animationWithduration... 在单独的线程中运行,并且看到我无法在类别中创建 iVar,我无法真正使用 @synchronized(someObject)..
有什么建议吗?
提前致谢!
编辑
方法如下:
-(void)showTopBannerWithHeight:(CGFloat)height andWidth:(CGFloat)width andMessage:(NSString *)message andDuration:(CGFloat)duration
{
UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, -height, width, height)];
[self.view.superview addSubview:messageLabel];
[UIView animateWithDuration:0.5
delay:0
options: UIViewAnimationOptionBeginFromCurrentState
animations:^{
messageLabel.frame = CGRectMake(0, 0, SCREEN_WIDTH, height);
}
completion:^(BOOL finished){
[UIView animateWithDuration: 0.5
delay:duration
options: UIViewAnimationOptionBeginFromCurrentState
animations:^{
messageLabel.frame = CGRectMake(0, -height, SCREEN_WIDTH, height);
}
completion:^(BOOL finished){
[messageLabel removeFromSuperview];
}];
}];
}
所以我从屏幕顶部显示一个“横幅”,等待一段时间(CGFloat)然后将视图滑出屏幕并删除。由于这是一个类别,我无法添加实例变量.. 所以我想要实现的是,如果多次调用此方法,我希望第一次调用无需等待即可执行,但之后的每个调用都等到前一个调用完成。
【问题讨论】:
-
你也想等到动画完成吗?
-
是的,查看编辑版本
标签: ios objective-c animation uiviewanimation synchronized