UINavigationController Custom CATransition - ios

I am trying to make a custom transition to push a view controller into the stack.
I dont know if there is an easy way to "lock" the navigationBar on its position and make the transition under the navigationBar.
I am using the following code:
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
First I tried the kCATransitionPush, but I could see the navigationBar moving down... so I tested kCATransitionMoveIn and it feels a bit better, but still not the way I wanted...
Is there a simple way to achieve this?

What you're doing is not how you do custom navigation controller transitions. You have to use the iOS 7 custom animator protocols (e.g. UIViewControllerAnimatedTransitioning).

Related

How to switch different views in one view controller

How to switch different views in one view controller.I have to design a app that has five views in one view controller and the views contains some text fileds.if i fill the text fileds in first view it should enter to the another view.that another view contains text fields.
Try this in Objective-C
Switch view with animation
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.superView addAnimation:transition forKey:nil];
[self.superView addSubview:self.chieldView];
Actually you can do it by using container view with changing alpha of your (5 views) so when you are on first view its alpha becomes 1 while others will be 0 and so on

Using animation for WebView page changes

I've been scouring the web looking for examples of how I could incorporate animation into my UIWebView control but am coming up blank.
I am not picky as to the animation (I can mess with it once I understand how to attach it to the actions), I just want something more than just a stark transition from one web page to another, curled pages, animation from left (old page) to right (new page), whatever will do.
Can someone post an example or direct me to a page that explains how I might do this? I read the docs on CATransition but I still don't see how to incorporate it into my UIWebView navigation.
After some playing around I got the effect I wanted, I probably need to tweak it a bit but here's what I came up with:
Before performing a loadRequest (and I've changed my code for now so that I capture all page changes via shouldStartLoadWithRequest and then set the new page manually using webview loadRequest) I go to a curl animation routine I wrote called animatePage:
- (void) animatePage
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0f];
animation.startProgress = 0.5;
animation.endProgress = 1;
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
[animation setType:#"pageCurl"];
//[animation setType:kcat];
[animation setSubtype:kCATransitionMoveIn];
[animation setRemovedOnCompletion:NO];
[animation setFillMode: #"extended"];
[animation setRemovedOnCompletion: NO];
[[myWebView layer] addAnimation:animation forKey:#"WebPageCurl"];
}
So to animate the page changes with a curling upward page animation I basically do:
[self animatePage];
[myWebView loadRequest:myRequest];
I can call the animatePage routine either before or after the loadRequest, it doesn't matter much.
I know this might not be the "right" way to get the job done but it does seem to get the job done. Like I said, I need to dial it in here and there but I'm happy with the result so far.
Using Swift:-
let animation = CATransition()//= [CATransition animation];
animation.delegate = self
animation.duration = 1.0
animation.startProgress = 0.5
animation.endProgress = 1
animation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionLinear)//kCAMediaTimingFunctionEaseInEaseOut)//kCAMediaTimingFunctionEaseOut
animation.type = "pageCurl"
animation.subtype = kCATransitionMoveIn
animation.isRemovedOnCompletion = false
animation.fillMode = "extended"
animation.isRemovedOnCompletion = false
webView?.layer.add(animation, forKey: "WebPageCurl")

how can i switch between two views using CATransition?

I have implemented in my code today a CATransition of type cube,
as I seen here, CATransition can be added to self.view.layer,
so my first question is if I can use my CATransition for switching between viewControllers and not just UIViews?
if I can't do it,
please look at this image:
http://up411.siz.co.il/up1/hnmim2mtjodt.png
as you can see, while the transition is in process, I see the same view of both faces of the cube,
I'd like it to be that one face presents view A and the other one presents view B
here is the code if needed :
self.view.layer.addAnimation(createTransition("Right"), forKey: "kCATransition")
func createTransition(side:String) -> CATransition{
var transition = CATransition()
transition.delegate = self
transition.duration = 0.6
transition.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")
transition.type = "cube"
transition.subtype = "from\(side)"
return transition
}
You have to add the same transition to the view layer of the second view controller's view as well.
Apple documentation in the Core Animation Programming Guide:
To perform a transition animation, you create a CATransition object and add it to the layers involved in the transition.

uipageviewcontroller and uiwebview in IOS

Here I have html content which is displayed using UIWebView. The webview is displayed in horizontal scrolling and which looks like scrolling page by page and currently I have implemented the normal pagecurl animation,Instead of using this animation I want to use the UIPageviewcontroller
CATransition *transition = [CATransition animation];
[transition setDelegate:self];
[transition setDuration:0.5f];
if(flipType==0)
[transition setType:#"pageUnCurl"];
else {
[transition setType:#"pageCurl"];
}
[transition setSubtype:#"fromRight"];
[theWebView.layer addAnimation:transition forKey:#"CurlAnim"];
Could you help me to implement this.
Its really easy you could just have a webview as the view of the viewcontrollers added to the
pageviewcontroller
there is an excellent tutorial about the same
here
kindly go through it.

UIView Animation slide in

I am trying to get my UIView to slide in from the right in the viewDidLoad method here's what I've got.
CGRect menuFrame = self.menu.frame;
menuFrame.origin.y = menuFrame.size.height+200;
[UIView animateWithDuration:1
delay:0.05
options: UIViewAnimationCurveEaseIn
animations:^{
self.menu.frame = menuFrame;
}
completion:^(BOOL finished){
NSLog(#"Animation Complete!");
}];
I am not sure what has gone wrong here I appreciate any help greatly.
This isn't what you asked, but it is worth saying anyway: viewDidLoad is a bad place for this code. viewDidLoad is called because the view controller has obtained its view, not because that view has appeared or will soon appear in the interface. It might soon appear in the interface, which is why your code has seemed to work up until now, but it might not.
The correct place for this code is probably viewWillAppear or viewDidAppear. You probably want to call this code only once, though, the first time the view appears. If you want to prevent the code from being called, because you've already animated menu into view on an earlier viewDidAppear call, simply include a conditional check to see whether menu already has a frame within the visible view.
By the way, another reason for avoiding things having to do with frames and bounds in viewDidLoad is that if your app launches into landscape and this is your root view, x and y are reversed.
It looks like you are trying to slide your menu in from the bottom as the Y position is pushed down initially by 200.
Usually you start by adding the view as a subview in its offscreen position and then set the onscreen position in the animation block.
And, make sure that you pass 1.0 as the animation duration.
use those transition.subtype for different effects
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.subtype = kCATransitionFromLeft; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
//transition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[appDelegate.navigation.view.layer addAnimation:transition forKey:nil];
viewController *DairyVC = [[viewController alloc] initWithNibName:#"viewController" bundle:nil];
[appDelegate.navigation pushViewController:DairyVC animated:YES];

Resources