Steaphann
Steaphann

Reputation: 2777

Changing UIViews height goes to the bottom but should go up

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?

enter image description here

Upvotes: 1

Views: 325

Answers (3)

bhavesh
bhavesh

Reputation: 109

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];

Upvotes: 0

Sanjay Mohnani
Sanjay Mohnani

Reputation: 5967

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.

Upvotes: 1

Manoj Mashru
Manoj Mashru

Reputation: 49

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;

Upvotes: 1

Related Questions