我正在尝试创建自定义弹出式提醒。将它添加到我的视图并为其设置动画效果都很好,但是在触发它时加载需要一段时间。
这就是我创建视图的方式。
@implementation SAActionAlertView
-(id)initWithTitle:(NSString *)title view:(UIView *)view;
{
self = [super init];
if (self){
self = [[[NSBundle mainBundle]loadNibNamed:@"ActionAlertView" owner:self options:nil]objectAtIndex:0];
self.actionAlertText.text = title;
self.view = view;
}
return self;
}
-(void)animate;
{
[self.view addSubview:self];
self.center = self.superview.center;
self.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
__block CGRect queueFrame = self.frame;
__block int queueY = queueFrame.origin.y;
[UIView animateWithDuration:.3 delay:.5 options:UIViewAnimationOptionCurveEaseOut animations:^{
queueY += 50;
self.frame = queueFrame;
self.alpha = .3;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}];
}
@end
这就是我在主视图控制器上呈现它的方式。
#pragma mark - Notification Center
-(void)trackQueued:(NSNotification *)notification
{
SAActionAlertView *actionAlert = [[SAActionAlertView alloc]initWithTitle:@"Track Queued" view:self.view];
[actionAlert animate];
}
视图显示和动画需要太长时间。我希望在触发事件时弹出即时。有关正确实现这一目标的任何想法?
答案 0 :(得分:0)
由于您在通知后执行动画,我假设您没有在主线程上运行。你应该。如果您在主线程以外的任何线程上执行UI更改,则无法确定它们何时实际反映在设备上的实际屏幕上。
- (void) trackQueued:(NSNotification *)notification {
dispatch_async(dispatch_get_main_queue(), ^{
SAActionAlertView *actionAlert = [[SAActionAlertView alloc]initWithTitle:@"Track Queued" view:self.view];
[actionAlert animate];
});
}