Hai all,
in my iphone application, when i click a UIButton it will show a UIDatePicker (using setVisible:YES) ,is there any way to animate the DatePicker appearance,(now when the user taps it will suddenly appear in the UI)
thanks in advance
Yes , it is possible to have an animation when you call your picker to set visible.
Initially your picker is hidden. When UIButton is pressed You just call below method (animatePicker).
In below method there is just hidden set to false for pickerview but with CAanimation.
-(void)animatePicker
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
// Set the type and if appropriate direction of the transition,
[animation setType:kCATransitionMoveIn];
[animation setSubtype:kCATransitionFromTop];
// Set the duration and timing function of the transtion -- duration is passed in as a parameter, use ease in/ease out as the timing function
[animation setDuration:0.4];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[[PickerView layer] addAnimation:animation forKey:#"transitionViewAnimation"];
PickerView.hidden = FALSE;
[[PickerView layer] removeAnimationForKey:#"transitionViewAnimation"];
animation = nil;
}
Note: Please include Quartz framework(QuartzCore.framework) and import its header file( QuartzCore/QuartzCore.h) to your controller.
A good idea is to bring it up like any other keyboard. Start it offscreen. Start an animation, set it to a position onscreen, then commit the animation. Otherwise you can do any other crazy view animation you want to do. Fade in, other slide animations, expand into view perhaps?
Related
I need to switch from 3 views of same viewcontroller. I am reaching it properly but I always get a fade transition. I do not understand how exactly works. Which parameter defines type of transition? setType or layer forKey:? I tried both but I always get same effect! Thank you
CATransition *trans =[CATransition animation];
trans.delegate = self;
[trans setDuration:2];
[trans setType:kCATransitionFromTop];
[trans setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
CALayer *layer = self.view.layer;
[layer addAnimation:trans forKey:kCATransitionMoveIn];
[self.view addSubview:vistaSocial];
To transition between multiple views you can simply use the +transitionFromView:toView:duration:options:completion: method of UIView. The options allow you to specify which type of transition you would like.
For example:
[UIView transitionFromView:view1 toView:view2 duration:0.35 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html
I'm currently performing a curl up animation by doing the following:
CATransition *animation = [CATransition animation];
animation.type = #"pageCurl";
animation.subtype = kCATransitionFromTop;
animation.fillMode = kCAFillModeForwards;
animation.duration = 1;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[[self.view.window layer] addAnimation:animation forKey:nil];
This animation will simply perform a page curl animation but in the end you are left looking at the same view that you started out with. No REAL transition ever occurred.
Now using animation blocks I know you can do something to the effect of:
[UIView transitionFromView:self.view
toView:aNewView // a view to transition to
duration:1
options:UIViewAnimationTransitionCurlUp|UIViewAnimationOptionCurveEaseIn
completion:NULL];
However, using animation blocks you are transitioning to a new view, aNewView, which is different from the CATransition animation above which reuses the same view (no real transition ever occurs). The problem with the animation block is that you have to actually create the new view to transition to which is cumbersome in my case because the view is rather complicated and I'd rather not create a UIView subclass.
Is there a way to perform the above CATransition animation using animation blocks while getting around the difficulties of having to rebuild a view or create a custom subclass?
Ok - so I figured it out for anyone who is interested. It's actually super simple. You can simply use the method: transitionWithView:duration:options:animations:completion:
For example:
[UIView transitionWithView:self.view
duration:1
options:UIViewAnimationOptionTransitionCurlUp|UIViewAnimationCurveEaseIn
animations:^{ // do anything you want here }
completion:NULL];
That's it. This will show a transition animation back to the same view. You can make any changes you want to the new view (maybe display some new text, whatever...) in the animation block.
I hope this helps someone out down the line...
I want to display a view with zoom out effect on click of a button and dissolve the view with a zoom in effect can you guide me to achieve this.
Thanx in advance
You can do it with a CAAnimation to the view's layer:
CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:#"transform.scale"];
[ani setDuration:0.5];
[ani setRepeatCount:1];
[ani setFromValue:[NSNumber numberWithFloat:1.0]];
[ani setToValue:[NSNumber numberWithFloat:0.1]];
[ani setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[myView layer] addAnimation:ani forKey:#"zoom"];
This adds an animation that makes the view shrink into its center. You might want to add set a delegate and implement animationDidStop:finished: in which you then hide the view and reset the layer's scale (see CAAnimation reference).
To create the opposite effect simply exchange the from and to values.
Also note that while the scale is not 1.0, the frame property is undefined. That is, if you try to move it or change its size while the layer's scale is not 1.0, strange things will happen.
I'm trying to add a sub view with Core-Animation using the attached code.
First time it happens as expected, but after that there's a flash of white in the place of the sub-view before it's fully pushed.
// Add the picker
viewToPush.frame = CGRectMake(0,185,320, 258);
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionMoveIn];
[animation setSubtype:kCATransitionFromTop];
[self.view addSubview:viewToPush];
[viewToPush.layer addAnimation:animation forKey:nil];
btw, in order to remove the subView I just use
[viewToRemove removeFromSuperview];
10x
Why do you add the animation to the viewToPush's layer, not the super view's? I suspect the layer of viewToPush is not stable as you remove the view from the super view. Do you have many views that can act as viewToPush or viewToRemove so they have to be dynamically allocated? Otherwise I would just change their hidden properties to implement such animations.
I am writing an app that needs to display a series of approximately 10-20 'views'. I have 4 view controllers and nibs that I would like to use. Each view has a forward and back button on it and the views should slide in either from the right or the left depending on the button pushed. I want to be able to reuse the nibs and controllers to present the information. I was trying to use a uinavigation controller, but ran into the problem that you can't push a view onto the stack more than once. The overall structure is a uinavigationcontroller within a tabbarcontroller. Is there a way to do this with a uinavigation controller, or should I try a different approach.
I would suggest making a container view controller class. It would create and "own" the four different view controllers you want to use. Then use something like this to switch between them:
// get the view that's currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view view
UIView *theWindow = [currentView superview];
// remove the current view and replace with newView
[currentView removeFromSuperview];
[theWindow addSubview:newView];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:#"SwitchToView1"];
(stolen from here)