0

在我打电话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;
}];
4

1 回答 1

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];
});
于 2015-10-03T16:22:12.887 回答