调用transitionWithView时iOS不需要的延迟:

时间:2015-10-03 15:22:48

标签: ios ios-animations

我在调用transitionWithView和动画实际在屏幕上开始之间的延迟时间很长(约6秒)。是因为我从处理程序或其他东西调用transitionWithView吗?

- (IBAction)saveToCal:(id)sender{
    LBWrapperView *wrapper = (LBWrapperView*)self.parentViewController;
    EKEventStore *store = [EKEventStore new];
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (!granted) { return; }
        EKEvent *event = [EKEvent eventWithEventStore:store];
        event.title = wrapper.lunch.title;
        ...
        event.calendar = [store defaultCalendarForNewEvents];
        NSError *err = nil;
        [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
        if (!err){
            [UIView transitionWithView:self.addToCalendarBtn duration:1.0 options:UIViewAnimationOptionCurveLinear animations:^{
                self.addToCalendarBtn.alpha = 0.0;
            } completion:nil];

        }
    }];
}

修改 调用时我也遇到同样的问题:

[UIView animateWithDuration:1.0 animations:^{
    self.addToCalendarBtn.alpha = 0.0;
}];

1 个答案:

答案 0 :(得分:1)

你确定你在主线程下运行吗?使用其他线程也会使用户界面操作滞后。

您可以使用以下代码将UI操作更改为主线程:

dispatch_async(dispatch_get_main_queue(), ^{
    [UIView transitionWithView:self.addToCalendarBtn duration:1.0 options:UIViewAnimationOptionCurveLinear animations:^{
            self.addToCalendarBtn.alpha = 0.0;
     } completion:nil];
});