English 中文(简体)
IOS UIView animation
原标题:IOS UIView animation
  • 时间:2011-11-02 02:32:04
  •  标签:
  • iphone
  • ios
- (void)showLabelAnimation
{
[UIView beginAnimations:@"animationID" context:nil];

[UIView setAnimationDuration:1];

//original rectangle is (0,0,100,50)

//and I want to change label to (100,100,200,100)
label.bounds = CGRectMake(100, 100, 200, 100);
label.frame = CGRectMake(100, 100, 200, 100);

[UIView commitAnimations];
}

It works well, but I just wondering why I have to set both bounds and frame of label. They seem like the same thing. Can anyone explains this for me? Thanks in advance.

[Edit in Nov 3rd] Thanks for your help, but when I remove the setbounds line, it doesn t work well, the label will be large immediately but move to new position by animation. The resize animation does not show up.

这是我所想的一件实事。

最佳回答

你们只能确定框架。 Bounds应自行更新。

Edit for additional help: Labels don t scale; changing the frame of it changes where the text is placed, but the size of the text does not scale this way.

但是,你可以把IDLabel s adjustsFontSize ToFitWidth 财产交给是的,然后在你掌握算术之前,就将体积确定在起算之前最多。 随着时间的推移,体积应当改变,以适应并实现你所期望的效果。

问题回答

The frame is the rectangle relative to the view s parent. The bounds is the rectangle relative to itself.

估算应在没有线的情况下进行。

label.bounds = CGRectMake(100, 100, 200, 100);

该法典正在对我工作。

    [UIView animateWithDuration:1
                 animations:^(void) {
                     self.leLabel.frame = CGRectMake(labFrame.origin.x, 
                        labFrame.origin.y + 100.0f, labFrame.size.width + 50.0f, labFrame.size.height);
                 }];

For what you want to do, you should only set the frame. If I change frame by bound in the previous code I will get a very strange behaviour.

因此,我猜测是你之所以需要确定这两个问题的原因,是因为你首先在经过约束和补充框架之后进行测试,以纠正因订立约束而产生的错误。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...