iphone – CGAffineTransformMakeRotation逆时针方向
我试图动画UI
ImageView动画逆时针旋转,当用户触摸它并沿顺时针方向移动其手指.
基本上我希望UIImageView一旦触摸结束就回到原来的位置,它应该以逆时针方向移动. 我遇到的问题是,每当角度(以度为单位)大于180时,图像就会顺时针旋转回原位.它显然走回了最短路径.对于179度或更小的角度,图像逆时针旋转(我需要的). 我尝试了这两段代码,它们的行为方式相同.有什么建议? 注意:这里的角度变量是一个double,它的初始值为零,在整个代码中它保持为0 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self handleObject:touches withEvent:event isLast:YES]; /* this doesn't make rotation counter clockwise for rotations greater than 180 */ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationCurve: UIViewAnimationCurveLinear]; [UIView setAnimationDuration:1.0]; [UIView setAnimationRepeatCount:1]; CGAffineTransform transform = CGAffineTransformMakeRotation(angle); circle1ImgVw.transform = CGAffineTransformRotate(transform,angle); // ends animation [UIView commitAnimations]; /* this doesn't make rotation counter clockwise for rotations greater than 180 */ [UIView animateWithDuration:1.0 animations:^{ circle1ImgVw.transform = CGAffineTransformMakeRotation(angle); }]; } 我试着调查this post并且有几个问题 >动画完成后,我无法再触摸和旋转图像 解决方法
我有一个类似的问题,检查接受的答案,它可能会帮助你:
Rotate a UIView clockwise for an angle greater than 180 degrees 在回应评论时,也许这会有所帮助: 在我的代码中我实际使用 rotationAnimation.fromValue rotationAnimation.toValue 代替 rotationAnimation.byValue. 如果toValue小于fromValue,则旋转始终为逆时针.如果你的价值观是积极的还是消极的,只关系它们之间的关系并不重要. 弄清楚你的起始角度是什么,找出你想要旋转的方向并找出你的结束角度是什么.如果你想逆时针方向,请确保它小于你的起始角度.这是我用于从12点到当前时间顺时针动画时钟指针的代码. -(void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self updateClockArmAngle]; } - (void)updateClockArmAngle { // Get the time NSDate *date = [NSDate date]; NSCalendar* calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; [calendar setTimeZone:[NSTimeZone timeZoneWithName:@"America/Toronto"]]; NSDateComponents* components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:date]; CGFloat hour = [components hour]; CGFloat angle = (hour/24.0)*(2*M_PI); CGFloat minute = [components minute]; angle += (minute/(24*60))*(2*M_PI); [self rotateViewAnimated:self.clockArm withDuration:1.5 byAngle:angle]; } - (void) rotateViewAnimated:(UIView*)view withDuration:(CFTimeInterval)duration byAngle:(CGFloat)angle { CABasicAnimation *rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; rotationAnimation.fromValue = 0; rotationAnimation.toValue = [NSNumber numberWithFloat:angle]; rotationAnimation.duration = duration; rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaSEOut]; [rotationAnimation setRemovedOnCompletion:NO]; [rotationAnimation setFillMode:kCAFillModeForwards]; [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |