我一直在尝试使用以下方法旋转按钮:
-(IBAction)rotate:(id)sender{
CGPoint pencilCenter = pencil.center;
[pencil setCenter:pencilCenter];
CGFloat floater = 1.0;
[UIView animateWithDuration:0.7 animations:^(void){
[pencil setTransform:CGAffineTransformMakeRotation(floater)];
}];
[UIView animateWithDuration:0.7 animations:^(void){
[pencil setTransform:CGAffineTransformMakeRotation(floater)];
}];
}
这应该使按钮进行某种“摇动”,然后它应该回到原来的位置 - 但它所做的只是改变按钮的位置,仅将其移动到一侧,然后在该方法的另一次运行中按钮没有反应at all.
我的代码有什么问题?
Thanks!
编辑2:
我的问题是 - 我如何制作一个按钮来进行一点摇动/摆动,例如编辑跳板时的摆动应用程序模式。
使用此代码可以让我向左旋转,从左到右然后从右到左平滑动画,然后旋转到原始位置。现在,我希望它不仅仅是旋转,而是用动画来实现,比如摆动。
[UIView animateWithDuration:0.25
delay:0.0
options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse)
animations:^ {
pencil.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(30));
pencil.transform = CGAffineTransformIdentity;
}
completion:^(BOOL finished){
}
];
Thanks!
导入“QuartzCore/QuartzCore.h”并尝试这个,
CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.delegate = self;
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 1.7;
fullRotation.repeatCount = 2;
[btnTemp.layer addAnimation:fullRotation forKey:@"360"];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)