下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
iOS提供了拍击、旋转、滑动、挤捏等丰富的手势,因此对图像的 *** 作就显得非常友好、简单。下面代码展示了使用UIGestureRecognizer对图像进行缩放 、移动、旋转 *** 作使用方法。在使用代码之前,首先建立一个UIVIEw,并在该视图中增加一个UIImageVIEw视图,用于展示图像。那么该UIVIEw就类似图 像画板一样,对图像的 *** 作都基于此视图中进行。- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; UIPinchGestureRecognizer *pinchRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)] autorelease]; [pinchRecognizer setDelegate:self]; [self.vIEw addGestureRecognizer:pinchRecognizer]; UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)] autorelease]; [rotationRecognizer setDelegate:self]; [self.vIEw addGestureRecognizer:rotationRecognizer]; UIPanGestureRecognizer *panRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)] autorelease]; [panRecognizer setMinimumNumberOftouches:1]; [panRecognizer setMaximumNumberOftouches:1]; [panRecognizer setDelegate:self]; [canvas addGestureRecognizer:panRecognizer]; UITapGestureRecognizer *tapProfileImageRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)] autorelease]; [tapProfileImageRecognizer setNumberOfTapsrequired:1]; [tapProfileImageRecognizer setDelegate:self]; [canvas addGestureRecognizer:tapProfileImageRecognizer];}
// 缩放-(voID)scale:(ID)sender { if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) { _lastScale = 1.0; } CGfloat scale = 1.0 - (_lastScale - [(UIPinchGestureRecognizer*)sender scale]); CGAffinetransform currenttransform = photoImage.transform; CGAffinetransform newtransform = CGAffinetransformScale(currenttransform,scale,scale); [photoImage settransform:newtransform]; _lastScale = [(UIPinchGestureRecognizer*)sender scale]; [self showOverlayWithFrame:photoImage.frame];}// 旋转-(voID)rotate:(ID)sender { if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { _lastRotation = 0.0; return; } CGfloat rotation = 0.0 - (_lastRotation - [(UIRotationGestureRecognizer*)sender rotation]); CGAffinetransform currenttransform = photoImage.transform; CGAffinetransform newtransform = CGAffinetransformRotate(currenttransform,rotation); [photoImage settransform:newtransform]; _lastRotation = [(UIRotationGestureRecognizer*)sender rotation]; [self showOverlayWithFrame:photoImage.frame];}// 移动-(voID)move:(ID)sender { CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInVIEw:canvas]; if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) { _firstX = [photoImage center].x; _firstY = [photoImage center].y; } translatedPoint = CGPointMake(_firstX+translatedPoint.x,_firstY+translatedPoint.y); [photoImage setCenter:translatedPoint]; [self showOverlayWithFrame:photoImage.frame];}
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的使用手势UIGestureRecognizer对图像进行缩放、移动、旋转 *** 作全部内容,希望文章能够帮你解决使用手势UIGestureRecognizer对图像进行缩放、移动、旋转 *** 作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)