On Dec 10, 2010, at 1:49 PM, Tharindu Madushanka wrote:

> Hi,
> Thanks.
> 
> But. This works with two views appearing as pushed. But I would like to have 
> animation for my next view controller.
> 
> But with two view controllers when other view controller shown, how could we 
> present that with similar animation.

Well, first it depends if you really want to present the next view in a modal 
state. In this case I would recommend to use 
-presentModalViewController:animated:. However, this high-level method is 
restricted to use built-in transitions. There is currently no built-in 
transition which looks like a "push animation" - for good reasons. For the 
available transitions please see the docs for UIModalPresentationStyle. There 
is also good documentation of how to use modal presented view controllers (look 
for "Modal View Controllers"). Basically, it's very easy to use it.



Otherwise, if you don't need or don't want the behavior of a modal presented 
view  (for instance, just simulating a push animation for a controller on a 
navigation stack) you can extend the previous example to use an extra view 
controller as well. Just create a new view controller, adjust its frame 
accordingly, setup views and so on. Then add this controller's view as a 
subview to the "main" controller's view. After that declare the transition as 
already shown. When you are finished with this view (using a similar 
transition), don't forget to clean up properly, for instance releasing the 
extra view controller (if necessary).


A few recommendation, though:

Really use a navigation controller if you actually have a navigation task. If 
you don't use a navigation controller, your implementation may suffer due to 
not automatically propagate -viewWillAppear, -viewDidAppear (etc.) and device 
rotation methods to your "detail" controllers. That is, your "detail" view 
controller will not receive these methods unless you add additional code.

If you have a "modal view" use case (that is, displaying an alert or warning, 
or in any case where a user input is required before doing anything else), you 
should implement this using the method -presentModalViewController:animated:. 



> 
> // animate up view with fade
>     CATransition *animation = [CATransition animation];
>     [animation setDuration:0.5];
>     [animation setType:kCATransitionPush];
>     [animation setSubtype:kCATransitionFromRight];
>     [animation setFillMode:kCAFillModeBoth];
>     [animation setTimingFunction:[CAMediaTimingFunction 
> functionWithName:kCAMediaTimingFunctionLinear]];
>     [[viewController.view layer] removeAllAnimations];
>     [[viewController.view layer] addAnimation:animation 
> forKey:@"pushAnimation"];
>     
>     [[viewController.view layer] 
> setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; // this is the 
> nearest I could get :(
>     [self presentModalViewController:viewController animated:YES];
> 
> But still it looks like dissolved and pushed.. not a real push ? :( How could 
> we do this with two view controllers ?
> 
> 
> Thanks a Lot,
> 
> Tharindu

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to