本文主要是介绍ios开发——手势识别(Rotation),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#import "ViewController.h"@interface ViewController () {//垃圾桶旋转角度CGFloat rotationAngleInRadians;
}@property(strong, nonatomic) UIImage *imageTrashFull;
@property(strong, nonatomic) UIImageView *imageView;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];//界面初始化CGRect screen = [[UIScreen mainScreen] bounds];CGFloat imageViewWidth = 128;CGFloat imageViewHeight = 128;CGFloat imageViewTopView = 300;CGRect frame = CGRectMake((screen.size.width - imageViewWidth) / 2, imageViewTopView, imageViewWidth, imageViewHeight);self.imageView = [[UIImageView alloc] initWithFrame:frame];[self.view addSubview:self.imageView];//创建图片对象self.imageTrashFull = [UIImage imageNamed:@"Blend Trash Full"];self.imageView.image = self.imageTrashFull;//创建Rotation手势识别器UIRotationGestureRecognizer *recognizer = [[UIRotationGestureRecognizer alloc]initWithTarget:selfaction:@selector(foundRotation:)];//Rotation手势识别器关联到imageView[self.imageView addGestureRecognizer:recognizer];//设置imageView开启用户事件self.imageView.userInteractionEnabled = YES;
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];
}- (void)foundRotation:(UIRotationGestureRecognizer *)sender {// 上一次角度加上本次旋转的角度self.imageView.transform = CGAffineTransformMakeRotation(rotationAngleInRadians + sender.rotation);// 手势识别完成,保存旋转的角度if (sender.state == UIGestureRecognizerStateEnded) {rotationAngleInRadians += sender.rotation;}
}@end
这篇关于ios开发——手势识别(Rotation)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!