Search code examples
iosobjective-cxcodeios8ios-app-extension

Animating the present and dismiss of a Share Extension with custom UI on iOS 8


I'm developing a Share Extension for iOS 8 with custom UI, but it appears without animation, how can I do this? It's a regular UIViewController.

Also, it appears on fullscreen on iPad and I want it to be a modal view controller, that appears in the center of the screen and doesn't fit it, how can I do this?

Regards.


Solution

  • Here is the cleanest solution I found so far to animate my custom view controller in and out!

    Animate IN:

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        self.view.transform = CGAffineTransformMakeTranslation(0, self.view.frame.size.height);
        [UIView animateWithDuration:0.25 animations:^
        {
            self.view.transform = CGAffineTransformIdentity;
        }];
    }
    

    Dismiss:

    - (void)dismiss
    {
        [UIView animateWithDuration:0.20 animations:^
        {
            self.view.transform = CGAffineTransformMakeTranslation(0, self.view.frame.size.height);
        } 
        completion:^(BOOL finished) 
        {
            [self.extensionContext completeRequestReturningItems:nil completionHandler:nil];
        }];
    }