【发布时间】:2011-08-10 22:31:08
【问题描述】:
我有一个图像“image1”,它是一个 UIButton,我想要的是,如果我触摸这个按钮,图像的宽度将乘以 2(带有动画),而不是高度只是宽度。 对不起我的英语我是法国人:/
【问题讨论】:
标签: iphone xcode animation uiimageview width
我有一个图像“image1”,它是一个 UIButton,我想要的是,如果我触摸这个按钮,图像的宽度将乘以 2(带有动画),而不是高度只是宽度。 对不起我的英语我是法国人:/
【问题讨论】:
标签: iphone xcode animation uiimageview width
这对于块动画来说相当容易。只需尝试:
imageView.contentMode = UIViewContentModeScaleAspectFit;
[UIView animateWithDuration:1.0
animations:^{
CGRect newRect = imageView.frame;
int movementToTheLeft = imageView.frame.size.width / 2;
newRect.size.width *= 2;
newRect.origin.x -= movementToTheLeft;
imageView.frame = newRect;
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
animations:^{
NSLog(@"Scaled!");// Anything can go in this completion block, it should be used for any logic you need after the animation.
}
completion:^(BOOL finished){
;
}];
这应该将您的 imageView 的宽度缩放 2。希望对您有所帮助!
【讨论】:
老式的方式(iOS 4.0 之后不推荐,但仍然有效):
[UIView beginAnimations:@"widen" context:nil];
[UIView setAnimationDuration:1.0];
CGRect newRect = imageView.frame;
newRect.width *= 2;
imageView.frame = newRect;
// ... set more parameters if desired
[UIView commitAnimations];
【讨论】: