关于手势问题的一些问题,图片旋转或者放大缩小,,需要指定锚点进行旋转或者缩放

来源:互联网 发布:keen.min.js是干嘛的 编辑:程序博客网 时间:2024/04/29 00:56
//设置图片的锚点- (void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view{    CGPoint oldOrigin = view.frame.origin;    view.layer.anchorPoint = anchorPoint;    CGPoint newOrigin = view.frame.origin;        CGPoint transition;    transition.x = newOrigin.x - oldOrigin.x;    transition.y = newOrigin.y - oldOrigin.y;        view.center = CGPointMake (view.center.x - transition.x, view.center.y - transition.y);}//设置回原来的锚点- (void)setDefaultAnchorPointforView:(UIView *)view{    [self setAnchorPoint:CGPointMake(0.5f, 0.5f) forView:view];}

其中,如果手势作用与图片上,那么久不需要转,如果不在图片上,那么久需要进行坐标转换convertPoint:toView: 或者 convertPoint: fromView========================================关于anchroPoint和position的关系,有如下的公式frame.origin.x = position.x - anchorPoint.x *bounds.size.width;frame.origin.y = position.y - anchorPoint.y *bounds.size.height;但是如果每次都要设置这种的话,麻烦,所以就有了上面的那两个方法,改变了anchorPoint而不改变layer的位置
阅读全文
0 0
原创粉丝点击