Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 386
Alvaro Franco Avatar asked Jul 16 '14 17:07

Alvaro Franco


People also ask

How do I present and dismiss a view controller in Swift?

How did you present the view controller? I did the mapping by setting a segue - "show", see the attached screenshot. Try to use modal. If you use push, you should dismiss it with the pop method of the navigation controller.

How do I present a view in Swift?

To present a ViewController in a NavigationController you can wrap ViewController into a NavigationController as it is in the example below. Then present NavigationController which contains ViewController. Check out the below video courses to learn more about Mobile App Development for iOS platform with Swift.


1 Answers

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];
    }];
}
like image 170
philouuuu Avatar answered Sep 20 '22 17:09

philouuuu