1。
@property (nonatomic, strong) UILabel *lbl;
@property CGFloat rotationAngleInRadians; //旋转的角度
- (void) handleRotations:(UIRotationGestureRecognizer *)paramSender{
if (self.lbl == nil){
return;
}
//label以中心为原点,进行的旋转 CG:Core Graphics
self.lbl.transform = CGAffineTransformMakeRotation(self.rotationAngleInRadians + paramSender.rotation);
if (paramSender.state ==UIGestureRecognizerStateEnded){
self.rotationAngleInRadians += paramSender.rotation;
}
}
- (void)initLabel {
self.lbl = [[UILabel alloc] initWithFrame:CGRectZero];
self.lbl.text = @"Hello, World!";
self.lbl.font = [UIFont systemFontOfSize:16.0f];
[self.lbl sizeToFit];
self.lbl.center = self.view.center;
[self.view addSubview:self.lbl];
}
-(void)addGesture {
UIRotationGestureRecognizer rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self
action:@selector(handleRotations:)];
[self.view addGestureRecognizer:rotationGesture];
}