我有一个图像“image1”,这是一个UIButton,我想要的是,如果我触摸这个按钮,图像的宽度乘以2(带动画)而不是高度只是宽度。 对不起我的英语我是法国人:/
答案 0 :(得分:3)
使用块动画这很容易。只需尝试:
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.希望有所帮助!
答案 1 :(得分:0)
老式的方式(在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];