在我的缩放和平移应用程序中,我正在使用上述手势识别器。这工作正常。 我想要一个按钮,将图像恢复到初始状态。这意味着显示实际图像或重置为初始状态。有人可以告诉我如何实现这个目标吗?
代码如下:
-(void)handlePanGesture:(UIPanGestureRecognizer*)recognizer
{
CGPoint translation = [(UIPanGestureRecognizer*)recognizer translationInView:[self superview]];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);
[(UIPanGestureRecognizer*)recognizer setTranslation:CGPointMake(0, 0) inView:[self superview]];
}
-(void)handlePinchGesture:(UIPinchGestureRecognizer*)recognizer
{
static CGRect initialBounds;
if (recognizer.state == UIGestureRecognizerStateBegan)
{
initialBounds = self.bounds;
}
CGFloat factor = [(UIPinchGestureRecognizer *)recognizer scale];
CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor);
self.bounds = CGRectApplyAffineTransform(initialBounds, zt);
}
答案 0 :(得分:0)
基于@ borrden的评论。
代码。根据需要进行更改。
UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseIn, animations: {
//Move image back to center
self.mainImageView.center = self.originalCenter!
self.layoutIfNeeded()
//Resize image to original
self.mainImageView.transform = CGAffineTransformIdentity
}, completion: nil
)