大家好,我想在单指触摸时旋转 UIView,它仍然会旋转,直到手指在 iPhone 的屏幕上移动,当我停止手指移动或将其从屏幕上移除时它会停止旋转。
提前致谢。
大家好,我想在单指触摸时旋转 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 提交动画];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}
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 的数字来比较它们,但我相信 Apple 更喜欢你使用这个或基于块的动画而不是旧系统。
旋转触摸视图可能会对您有所帮助