How to make UIView move by click? - ios

I'm not sure whether I can describe it properly. It's a kind of UIView, and we see only it's part (with arrow,maybe. on the bottom of screen,maybe). User can click on it, and this view appears fullscreen(usually developer leaves there some additional information). How can I make it?

Try this:
-(void)show
{
[viewObj setFrame:CGRectMake(viewObj.frame.origin.x,viewObj.frame.origin.y,viewObj.frame.size.width, viewObj.frame.size.height)];//Here "viewObj.frame.origin.y" means 568
[UIView animateWithDuration:0.5 animations:^
{
[viewObj setFrame:CGRectMake(viewObj.frame.origin.x,0,viewObj.frame.size.width, viewObj.frame.size.height)];
}
completion:^(BOOL finished)
{
}];
}
-(void)hide
{
[viewObj setFrame:CGRectMake(viewObj.frame.origin.x,viewObj.frame.origin.y,viewObj.frame.size.width, viewObj.frame.size.height)];//Here "viewObj.frame.origin.y" means 0
[UIView animateWithDuration:0.5 animations:^
{
[viewObj setFrame:CGRectMake(viewObj.frame.origin.x,568,viewObj.frame.size.width, viewObj.frame.size.height)];
}
completion:^(BOOL finished)
{
}];
}

i just put the logic that just setting of view Y coordinate of That View and when user click on Button. that et animation and at the re setting the view frame with Y coordinate setting like:
yourview.frame = CGRectMake(0,280,320,568);
[UIView animateWithDuration:2
delay:0.1
options: UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
yourview.frame = CGRectMake(0, 0, 320, 568);
}
completion:^(BOOL finished){
}];
Also see this example:
https://github.com/crocodella/PullableView
Here above github demo this same that you are looking for its output like:

Look at UIView reference:
https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html
Specifically:
#property(nonatomic) CGPoint center
And
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
Example:
[UIView animateWithDuration:2.0 animations:^{
myView.center = CGPointMake(self.view.center.x, self.view.center.y + myOffset);
}];
Duration is in seconds. In this case, 2 seconds.
If you're using AutoLayout, you probably want to change the layout constant, rather then center property.
About Layout Constrains:
https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/NSLayoutConstraint/NSLayoutConstraint.html
Look at constant property. You can also drag a constrain outlet from Interface Builder and access its constant. It's really simple once you get to know it a bit.

Related

Bouncing animation while changing view frame

Add bouncing animation while changing UIVIew frame. I only know how to change frame but I don't know how to set bouncing effect while changing view frame. Below is my code....
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
CGRect frame = viewContent.frame;
frame.size.height = CGRectGetHeight(viewContentFullDetail);
viewContent.frame = frame;
} completion:^(BOOL finished) { }];
You can check animated gif image on below link. I want to add animation not same like this but near to this. Main animation are unfolding and bouncing effect.
https://drive.google.com/open?id=0B9k_Shyb5v62eFdxWXhYeXV3a0E
Please help. I don't know how to do this.
You need to try this
int duration, damping, velocity;
[UIView animateWithDuration:duration delay:0
usingSpringWithDamping:damping initialSpringVelocity:velocity
options:0 animations:^{
// your animation code here
} completion:nil];
Play with the damping and velocity values to know more about this feature in the animation code.
here is the link for a tutorial

Showing UIView with bouncy animation

I want to create a bouncy animation like in the Skitch application - when i press a button, a subview (simple view with several buttons) will appear from the side and will bounce a bit until it stops.
I can't find any standard animation that does that, so how i can implement this animation?
You can try this :
// Hide your view by setting its position to outside of the bounds of the screen
// Whenever you want, call this :
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.5
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
// Set your final view position here
}
completion:^(BOOL finished) {
}];
This method is the same as the usual animateWithDuration: but it introduces a spring animation.
Use UIView method:
+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
usingSpringWithDamping:(CGFloat)dampingRatio
initialSpringVelocity:(CGFloat)velocity
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
This will do what you want
Use the UIView method, If you want bouncing effect. Then you need to nested the animation process and give the frame as needed for that view. Here's the example:
CGRect frameOnStart = CGRectMake(200,200 ,60 ,60); //On start show small view
CGRect frameOnAnimate = CGRectMake(80,80 ,150 , 150); //while animate show large view
CGRect frameAfterAnimate = CGRectMake(100,100,120 ,120); //after animate large take it back to original frame. SO it loos like bouncing animation
// Whenever you want, call this :
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.5
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
// Set your on Animate position here
view.frame = frameOnAnimate;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.5
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
// Set your final view position here
view.frame = frameAfterAnimate;
}
completion:^(BOOL finished) {
}]
}];
Thanks.

How to animate UISearchbar frame change keeping the rounded caps?

I would like to animate the frame change of the UISearchbar. I would like it to expand and collapse when tapped on a search button.
Am using UIViewAnimationBlock to animate
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
//Set the frame you want to the search bar
}
completion:^(BOOL finished) {
}];
I have to expand the frame from zero and collapse it back. But while animating, the search bar loses its rounded edges and becomes a rectangle. Here is a screenshot of it while still animating
Well it doesn't look good.. I want it to keep its rounded edges while expanding or collapsing. Is it possible ? If yes how ?
Any help would be much appreciated.
You can not change height of a UISearchBar try setting frames with height of 44px.
And if you want to change height then use CGAffineTransformMakeScale like..
//FOR EXPAND USE THIS:
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
self.searchBar.transform = CGAffineTransformMakeScale(1.0, 1.0);
}
completion:^(BOOL finished) {
}];
and
//FOR EXPAND USE THIS:
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
self.searchBar.transform = CGAffineTransformMakeScale(0.001, 0.001);
}
completion:^(BOOL finished) {
}];

Flip and Rotate

I have 2 views. I would like a card to flip and rotate along its axis to show the other view.
So when I click on view1, view1 should flip but flip in the sense that it rotates around the y-axis to show view 2.
I am using the FLIP directive in IOS, but that does not do the "rotate" that I am looking for:
[UIView transitionFromView:(self.displayingPrimary ? self.primaryView : self.secondaryView)
toView:(self.displayingPrimary ? self.secondaryView : self.primaryView)
duration: 2.0
options: (self.displayingPrimary ? UIViewAnimationOptionTransitionFlipFromLeft :
UIViewAnimationOptionTransitionFlipFromRight) | UIViewAnimationOptionShowHideTransitionViews
completion:^(BOOL finished) {
if (finished) {
self.displayingPrimary = !self.displayingPrimary;
}
}];
There are a couple of ways you can make one view flip to another using Quartz on iOS if you do not like the built in flip transformation. The following two code snippets both require you to #import <QuartzCore/QuartzCore.h> and also link against the QuartzCore framework. Note that both functions I wrote assume that both views are added as subviews with the same frame and one of them is hidden (setHidden:).
The first function will flip one view to another using 2D transformations. This is more efficient and all it really does is scale along the x axis. At high speeds, it looks pretty good, IMO.
+ (void)flipFromView1:(UIView*)v1 toView:(UIView*)v2 duration:(NSTimeInterval)duration completion:(void (^)(BOOL finished))completion
{
duration = duration/2;
[v2.layer setAffineTransform:CGAffineTransformMakeScale(0, 1)];
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[v1.layer setAffineTransform:CGAffineTransformMakeScale(0, 1)];
} completion:^(BOOL finished){
[v1 setHidden:YES];
[v2 setHidden:NO];
}];
[UIView animateWithDuration:duration delay:duration options:UIViewAnimationOptionCurveEaseOut animations:^{
[v2.layer setAffineTransform:CGAffineTransformMakeScale(1, 1)];
} completion:completion];
}
The second function performs an actual 3D transformation. Note that if the views being rotated using this 3D transformation are over or under other subviews in 3D space then you could see those other views sticking through or getting hidden during this animation.
+ (void)flipFromView2:(UIView*)v1 toView:(UIView*)v2 duration:(NSTimeInterval)duration rToL:(BOOL)rToL completion:(void (^)(BOOL finished))completion
{
duration = duration/2;
v2.layer.transform = CATransform3DMakeRotation((rToL ? -1.57079633 : 1.57079633), 0, 1, 0);
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
v1.layer.transform = CATransform3DMakeRotation((rToL ? 1.57079633 : -1.57079633), 0, 1, 0);
} completion:^(BOOL finished){
[v1 setHidden:YES];
[v2 setHidden:NO];
}];
[UIView animateWithDuration:duration delay:duration options:UIViewAnimationOptionCurveEaseOut animations:^{
v2.layer.transform = CATransform3DMakeRotation(0, 0, 1, 0);
} completion:completion];
}

How do I get the smoothest animation possible in iOS?

I'm using the UIView method animateWithDuration:animations to animate sliding a UIView. It appears slightly choppy. Is there a better method, like CoreGraphics, to accomplish a smoother animation?
You can try to use different UIViewAnimationOptions
The default is UIViewAnimationOptionCurveEaseInOut, but you can try others:
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
v.center = CGPointMake(400, 400);
}
completion:^(BOOL finished) {
}
];

Resources