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

iOS unwanted delay when calling transitionWithView:

我在调用 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;
}];

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

您可以使用下面的代码来改变您对主线程的 UI 操作:

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