Search code examples
iosios-animations

iOS unwanted delay when calling transitionWithView:


I'm getting a really long (about 6 seconds) delay between when I call transitionWithViewand when the animation actually starts on the screen. Is it because I am calling transitionWithView from a handler or something?

- (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];

        }
    }];
}

Edit: I also have the same problem when calling:

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

Solution

  • Are you sure you're running under main thread? Using other threads also make User interface manipulation laggy.

    You can use below code to changing you're UI manipulation to main thread:

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