Iphone UIView旋转
您好,我想在单指触摸上旋转UIView,它仍然旋转,直到手指在iPhone屏幕上移动,当我停止移动手指或将其从屏幕上移除时,它停止旋转 提前感谢。尝试类似的代码 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.2]; CGAffineTransform rr=CGAffineTransformMakeRotation(5); yourView.transform=CGAffineTransformConcat(yourView.transform, rr); [UIView commitAnimations]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self touchesBegan:touches withEvent:event]; } -(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件{ [UIView beginAnimations:nil上下文:NULL]; [UIView设置动画持续时间:0.2]; CGAffineTransform rr=CGAffineTransformMakeRotation(5); yourView.transform=CGAffineTransformConcat(yourView.transform,rr); [UIView委员会]; } -(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{ [自我接触开始:接触事件:事件]; } 尝试类似的代码 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.2]; CGAffineTransform rr=CGAffineTransformMakeRotation(5); yourView.transform=CGAffineTransformConcat(yourView.transform, rr); [UIView commitAnimations]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self touchesBegan:touches withEvent:event]; } -(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件{ [UIView beginAnimations:nil上下文:NULL]; [UIView设置动画持续时间:0.2]; CGAffineTransform rr=CGAffineTransformMakeRotation(5); yourView.transform=CGAffineTransformConcat(yourView.transform,rr); [UIView委员会]; } -(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{ [自我接触开始:接触事件:事件]; }Iphone UIView旋转,iphone,objective-c,uiview,cgaffinetransform,Iphone,Objective C,Uiview,Cgaffinetransform,您好,我想在单指触摸上旋转UIView,它仍然旋转,直到手指在iPhone屏幕上移动,当我停止移动手指或将其从屏幕上移除时,它停止旋转 提前感谢。尝试类似的代码 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.2]; CGAffineTra
Pradeepa的代码很好,但是,动画系统正在被弃用(如果还没有的话)。请尝试以下方法:
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
double startRotationValue = [[[yourView.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] doubleValue];
rotation.fromValue = [NSNumber numberWithDouble:startRotationValue];
rotation.toValue = [NSNumber numberWithDouble:startRotationValue+5];
rotation.duration = 0.2;
[yourView.layer addAnimation:rotation forKey:@"rotating"];
我采用了Pradeepa的数字使它们具有可比性,但我相信苹果更喜欢你使用这种或基于块的动画,而不是旧的系统。Pradeepa的代码很好,但是,动画系统正在被弃用(如果还没有的话)。请尝试以下方法:
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
double startRotationValue = [[[yourView.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] doubleValue];
rotation.fromValue = [NSNumber numberWithDouble:startRotationValue];
rotation.toValue = [NSNumber numberWithDouble:startRotationValue+5];
rotation.duration = 0.2;
[yourView.layer addAnimation:rotation forKey:@"rotating"];
我采用了Pradeepa的数字使它们具有可比性,但我相信苹果更喜欢你使用这种或基于块的动画,而不是旧的系统。可能会帮助你