UIButton的动画
答
试试这个,这是一个简单的例子,将50像素的动画按钮,然后右后卫试(别忘了IB链接为myButton) -
.H -
@property (nonatomic, retain) IBOutlet UIButton *myButton;
.m -
@synthesize myButton;
-(IBAction)myButtonPressed {
CGPoint oldCentre = myButton.center;
CGPoint newCentre = myButton.center;
newCentre=CGPointMake(newCentre.x + 50.0, newCentre.y);
[UIView animateWithDuration:0.3
delay:0.0
options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
myButton.center = newCentre;
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.3
delay:0.0
options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
myButton.center = oldCentre;
}
completion:nil
];
}
];
}
您可以在块中放入任何喜欢的动画。
你可能要考虑摆脱UIViewAnimationOptionAllowUserInteraction位作为可能会有一些有趣的结果,如果用户保留在动画期间触摸按钮...
+0
很高兴听到它:) – SomaMan 2012-04-16 09:51:35
从这里http://*.com/ a/1679402/932011 – akk 2012-04-16 09:02:20
感谢您的链接,但我必须使用这些块。我怎样做? – 2012-04-16 09:08:41
这个问题有什么问题?为什么倒票? – SomaMan 2012-04-16 11:21:33