Coder Social home page Coder Social logo

custommodaltransition's Introduction

Custom modal transition

A custom transition I developed for one of my apps. It works on iOS 7 - iOS 8.2.

UIPresentationController update (iOS 8 only)

A solution using UIPresentationController and without iOS 7 hacks can be found in ios8 branch. It features properly handled appearance events, device orientations support and much less code.

Caveats

  • Controllers will not properly rotate if orientation changed when presented. There is only one exception, if presented controller is a navigation controller, then rotation works fine. This seems to be a UIKit bug on iOS 7 or iOS 8. UIPresentationController solves that problem by providing a way to resize controllers on orientation change.

  • State restoration is possible but presented VC should restore transitioningDelegate, modalPresentationStyle and modalPresentationCapturesStatusBarAppearance. If you use storyboards then it's easy:

    - (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
      [super encodeRestorableStateWithCoder:coder];
      
      [coder encodeInteger:self.modalPresentationStyle forKey:@"modalPresentationStyle"];
      [coder encodeInteger:self.modalPresentationCapturesStatusBarAppearance forKey:@"modalPresentationCapturesStatusBarAppearance"];
      [coder encodeObject:self.transitioningDelegate forKey:@"transitioningDelegate"];
    }
    
    - (void)decodeRestorableStateWithCoder:(NSCoder *)coder {
      [super decodeRestorableStateWithCoder:coder];
    	
      self.modalPresentationStyle = [coder decodeIntegerForKey:@"modalPresentationStyle"];
      self.modalPresentationCapturesStatusBarAppearance = [coder decodeIntegerForKey:@"modalPresentationCapturesStatusBarAppearance"];
      self.transitioningDelegate = [coder decodeObjectForKey:@"transitioningDelegate"];
    }

Blog post

This project is a part of my blog post. However lots of things changed since original blog post was published.

  • Unwinding works fine if you fix segueForUnwindingToViewController in source navigation controller and create unwind segue using source view controller. Works for both iOS 7 and 8 (see http://stackoverflow.com/a/28607309/351305)
  • Resetting views' frames to container bounds before adding them to container helps to solve issues with misplaced navigation bar and rotation issues on iOS 7.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.