How to present popover with animations? - ios

Currently, I'm using presentPopoverFromRect:inView:permittedArrowDirections:animated: to present my popover. But I'm looking for more fanciful animations (eg. the popover expanding from a particular point) to present the popover.
I've tried searching with keywords ios present popover animation but can't find any useful results. Not sure if I'm using the wrong keywords or it is impossible to present popovers with animations.

When using a UIPopover, there is currently no easy way to present it with a different animation than the one that iOS provides. It would definitely be possible to do a custom animation to present a view, but it would be a very significant amount of extra work as you would have to do everything yourself. Two things you could look at if you really, really need to:
UIView animation. Links: Ray Wenderlich tutorial, Apple documentation (search the page for "animation").
Core Animation custom transitions.

As of iOS 7.0 it is possible to present any view controller so that it does not completely obscure the previous view controller, making it possible to create "fake" popovers. Using the UIViewControllerTransitioningDelegate protocol you can then create any animation you would like.
Here is a good example of how to create a fake popover with a custom animation.

Related

Name of iOS ui element

How does this half screen scrollable pop up elememt is called in iOS? Have seen it in many apps so I guess it should be native one.
Even though it's common, it is not a standard UIKit element. It's a custom presented view controller (not a standard configuration). You'll need a custom transition animation and presentation controller along with gesture recognizers for dismissal. (There are lots of tutorials showing you how to do that.)
New in iOS 13, all presented view controllers have this general configuration by default (called "sheet" or "card"), but not half-screen like the one you've shown (they almost fill the screen).

How to implement page switch by scroll gesture which is already implemented in iOS7?

It's nice that back to previous page is so easy by swipe gesture in iOS7, Apple has implemented for you already. We like this feature, but how to implement it on iOS6? Any resource can take reference? Such as open source or design solution.
Please share and thanks in advance.
I'd probably be inclined to use UIPageViewController (which is a nice control that offers swiping between view controllers). If you really want to reproduce the UINavigationController iOS 7 UI (swiping from edges rather than anywhere on the page, all of the navigation bar UX, etc.), it might take a little work. But if all you need is a nice simple swiping between view controllers, UIPageViewController might be a good place to start.
See the Page View Controllers section of the View Controller Catalog for iOS.

Best way of handling pan gestures

I want to handle transitions between two instances of the same view controller class, using pan gestures.
I've read almost every transitions can be handled by segues, but is it the same when using pan gestures?
Segues don't seem to be a good fit for this kind of transitions.
For the moment, I have a master view controller which instantiates to sub view controllers. The gesture related code resides in the master view controller.
It works well, but I believe there has to be a solution where all the controller management stuff is done in the storyboard.
What is the best place in my code to handle this kind of transitions?
It sounds to me like what you want is a UIPageViewController set up to scroll instead of page curl (That's a settable property) A page view controller would do all the work for you.
There is a sample app in the Xcode docs called PhotoScroller that shows how to set this up. It does lots of other stuff too, (pinch to zoom and image tiling) but you can ignore that.
If you can't get a UIPageViewController to give you the transition you want then you might need to build your own custom parent view controller class. Embedding a single child using a container VC and an embed segue is trivial. I haven't tried to embed multiple children in the same container yet. using embed segues yet. I've done transitions between child VCs using the "manual" parent/child VC calls that were added in iOS 5
I've found a really great article on the way to implement custom transitions with iOS 7, whether they're interactive or not: http://www.captechconsulting.com/blog/tyler-tillage/ios-7-tutorial-series-custom-navigation-transitions-more
It comes with a very detailed demo.
Animations should be classes implementing the UIViewControllerAnimatedTransitioning or UIViewControllerInteractiveTransitioning protocols.
The code using the gesture recognizer can reside in those classes.
The animation can then be returned in the following methods of your navigation controller delegate:
navigationController:animationControllerForOperation:fromViewController:toViewController:
navigationController:interactionControllerForAnimationController:
This way I can plug the animation to whatever controller I want to.
I hope it could help someone.

The right way to present view controller with custom transition/animation in iOS<7

I want to present view controllers as simple as with native presentViewController:animated:completion:, dismissViewControllerAnimated:completion: methods, but use custom animations for this.
The common way to do this is to perform custom animation (using view screenshots instead of view itself) and call presentViewController:vc animated:NO completion:… after.
But in this case view controller life-cycle messages are sent not in time. viewWillApper: and viewDidAppear: sent together instead of normal way: the first one just before animation and the last — after. Also they sent with animated parameter set to NO.
The other bad thing is that screenshot of a view (for animation) captured before viewWillApper: called. So it can be some outdated, and this will cause flicking at the end of animation.
I've searched lot of related projects on github/cocoapods (SO answers too), but did not find any with the right life-cycle of presented view controller. There are sometimes even worse solutions like simple views changing without any calls to life-cycle methods.
Possible solutions I know:
iOS7 — I can't, I need it in iOS6 too
Use transition between contained view controllers — Not as simple and reusable as "modal presenting"
Use tricky animations like here — my animation can't be implemented in similar way
While writing this question I thought about custom segue with overridden perform: method. But looks like it's not easy too. At least I don't know how to use it without storyboard and how to do dismiss in easy way.
Do you know how to present view controller with custom animation in iOS6 and make it's life-cycle happy?
Update: finally I've decided to use container view controller. It has ability to customize transitions of it's children and preserve VC's life-cycle. The bad side: it's not as easy as custom transitions in iOS7. It needs container, making xib some harder. And needs additional code to support.

multiple "content views" on the same xib

I have a ViewController (with navigation) that needs to show 7 different content layouts. I want to keep the same background and nav, the only thing that needs to change is the central UIView.
If I have 7 different UIViews on the same xib/storyboard, can I hide the ones I'm not using or will that ding performance?
Using segues won't work either because they make a mess out of my custom navigation and animations.
Is there a better way to accomplish what I am trying to do? Thanks for suggestions
solution
My design is too custom for using view controller containment so I decided to mimic the idea with a custom UIViewController and two UIViews. It's not too bad and it works rather quickly.
You should look into using view controller containment, then you can load your views from separate nib files and still provide your custom navigation and animations from your container view controller.
Note: This is only really supported from iOS 5.
Generally, it's a good idea to unload views that aren't visible, however, if your views aren't using too much memory (and/or cpu time) hiding them when they're not in use should work fine.
View controller containment is probably what you should be doing if each view has its own unique functionality (i.e. view 1 is a map, view 2 shows some about text, view 3 is an image gallery). UITabBar might be useful, but it depends on your app.
The performance hit would depend on your views' contents. If you haven't done so already, invest some time into learning how to use Instruments (apple's diagnostic tool). Watching the video titled "Optimizing App Performance with Instruments" in the developer resources would be a good start.
My design is too custom for using view controller containment so I decided to mimic the idea with a custom UIViewController and two UIViews. It's not too bad and it works rather quickly.

Resources