Changing UIViews height goes to the bottom but should go up - ios

I want to do a bar-graph animation. Where the bars go up when the view loads. Here is what I do.
CGRect bar1Frame = self.rootView6.bar1.frame;
bar1Frame.size.height = 181;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
self.rootView6.bar1.frame = bar1Frame;
[UIView commitAnimations];
The problem is that the bars height goes to the bottom of the view instead of going to the top.
Anyone can help me?

You need to update the y origin of the bar1Frame as well with
bar1Frame.origin.y = bar1Frame.origin.y - 181;
bar1Frame.size.height = 181;
and apply the animations as you did. Doing so will show your bar above the horizontal line of the graph.

You need to change the y-position of the UIView.
Eg: if you need to change height to 100 then
bar1Frame.origin.y = bar1Frame.origin.y-100;

CGRect bar1Frame = self.rootView6.bar1.frame;
bar1Frame.size.height = 181;
bar1.Frame.origin.y -= bar1Frame.size.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
self.rootView6.bar1.frame = bar1Frame;
[UIView commitAnimations];

Related

Slow down UIView animation like as the dropdown Menu in iOS

I have a problem with animation show UIView slow down like as dropdown menu. I tried below code but it so fast.
Can you help me to correct it? Thanks.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
blockView.frame = CGRectMake(newFrame.origin.x, newFrame.origin.y , newFrame.size.width, newFrame.size.height + *h);
[blockView addSubview:dropDownView];
[UIView commitAnimations];
I want to make UIView slow down like as the Expedia app. Please give me some advice.
Thanks in advance.
Just increase the AnimationDuration based on how much slow u want to make your drop down.
Exmaple:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.5];
self.blackView.frame = CGRectMake(newFrame.origin.x, newFrame.origin.y , newFrame.size.width, newFrame.size.height + h);
[self.blackView addSubview:self.dropDownView];
[UIView commitAnimations]
if u feel your dropDownView attached before the animation gets complete means u can use following code to attach your dropDownView at end of the animation completion.
[UIView animateWithDuration:5.5
animations:^{
self.blackView.frame = CGRectMake(newFrame.origin.x, newFrame.origin.y , newFrame.size.width, newFrame.size.height + h);
}
completion:^(BOOL finished){
[self.blackView addSubview:self.dropDownView];
}];
Use the options in UIView animation
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
// ... do stuff here
} completion:NULL];

UILabel always animates to same spot

I have a UILabel called "nameLabel" and I have it inside an animation block so that this happens:
_nameLabel.alpha = 1;
CGAffineTransform translate = CGAffineTransformMakeTranslation(50, 50);
_nameLabel.transform = translate;
I thought that animates the UILabel to the spot I specify but it just animates from the above spot to the place where I have it in the Interface Builder. Any help here?
Can you post the animation block and other associated code? I am not sure what CGAffineTransformMakeTranslation does with the label, but if you want to animate the frame location, you can use this:
CGRect frame = _nameLabel.frame;
frame.origin.y = 100; //Desired height, origin.x can be modified as well.
//You can also change the frame size here but it wont work on UILabels, you will need `CGAffineTransformScale` for that.
[UIView animateWithDuration: 1.5
delay:0.0
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^ {
[_nameLabel setFrame:frame];
}
completion:^ (BOOL finished) {
}];
Edit: The other way:
CGRect frame = _nameLabel.frame;
frame.origin.y = 100;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[_nameLabel setFrame: newFrame];
[UIView commitAnimations];
Current state is probably the current location of the label, try that first but if nothing happens, remove UIViewAnimationOptionBeginFromCurrentState or set the frame of the label to another location before the animation, and move it to its initial (the one in the xib file) position in the animation block, its your call.
Watch out because Autolayout cause a lot of problems.
Try to deselect 'Use Autolayout'
It solves to me all the problems trying to translate objects.

How to animate overlay drawing in MKMapView

I'm drawing MKCircleView overlay on MKMapView. it works fine, except that I need to animate drawing of this overlay.
I know that I need to use:
[UIView beginAnimations:nil context:NULL];
[UIView commitAnimations];
,but I don't know where to put this animation code.
Thanks.
not sure what you're looking for.. but for example:
[UIView beginAnimations:#"fade" context:nil];
[UIView setAnimationDuration:0.6f];
theView.alpha = 0.0f;
theView.transform = CGAffineTransformMakeScale(0.01,0.01);
theView.alpha = 1.0f;
[UIView commitAnimations];

unclear resize UIWebView behavior

I am trying to resize a UIWebView like this:
CGRect oldFrame = zoomView.frame;
zoomView.layer.anchorPoint = CGPointMake(1, 0.5);
zoomView.frame = oldFrame;
if (oldFrame.size.width == 1024) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
zoomView.frame = CGRectMake(512, 0, 512, 470);
[UIView commitAnimations];
} else {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
zoomView.frame = CGRectMake(0, 0, 1024, 470);
[UIView commitAnimations];
}
The resize works, but the content of the Webview won't follow the resize. It looks like the content get set to the new bounds first and then the View resizes. In the case from 1024 width to 512, the content get set to 512 width directly and then the view shrinks to its new size and position.
What do I oversee here?
Seems it this is the way how animating size and origin get animated. The scrollview won't get updated during this. Solved it by using an own timer and move the view myself.

Animate transitions in UIScrollView

I have a UIScrollView that holds UIImageViews.
I'd like to animate the transition between views using a fading style. So, if we are at index 0, and we move on, the image at index 1 will display OVER the image 0.
Any help?
Thank you!
A really simple way of fading between two views:
saveFrame = self.imageView2.frame;
self.imageView2.frame = self.imageView1.frame;
self.imageView2.alpha = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
self.imageView1.alpha = 0;
self.imageView2.alpha = 1;
[UIView commitAnimations];

Resources