当前位置: 移动技术网 > 移动技术>移动开发>IOS > ios 双指捏合放大缩小图片的例子

ios 双指捏合放大缩小图片的例子

2019年05月12日  | 移动技术网移动技术  | 我要评论

 


图片跟随双指捏合的距离放大或者缩小。

 


利用-(void)touchesmoved:(nsset *)touches withevent:(uievent *)event  实现。

touchesmoved每当手指在屏幕上移动的时候都会运行。

 


1.检测手指的个数

nsarray * touchesarr=[[event alltouches] allobjects];
nslog(@"手指个数%d",[touchesarr count]);

 


2.检测两指的坐标,从而计算两指的距离。

    p1=[[touchesarr objectatindex:0] locationinview:self.view];
    p2=[[touchesarr objectatindex:1] locationinview:self.view];

 


3.计算距离增加,则增大图片,距离减小则缩小图片。用imageview的frame来控制图片的大小。


 imageview.frame=cgrectmake(imgframe.origin.x-addwidth/2.0f, imgframe.origin.y-addheight/2.0f, imgframe.size.width, imgframe.size.height);

 

 

 


 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网