Commit af8e692b authored by zhu's avatar zhu

no message

parent 02070814
...@@ -44,14 +44,33 @@ ...@@ -44,14 +44,33 @@
self.backgroundColor = [UIColor clearColor]; self.backgroundColor = [UIColor clearColor];
[self setUserInteractionEnabled:YES]; [self setUserInteractionEnabled:YES];
[self setMultipleTouchEnabled:YES]; [self setMultipleTouchEnabled:YES];
// 旋转手势
// 旋转 UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateView:)];
UIRotationGestureRecognizer *rotateGes = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)]; [self addGestureRecognizer:rotationGestureRecognizer];
[self addGestureRecognizer:rotateGes];
// 缩放手势
// 放大缩小 UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchView:)];
UIPinchGestureRecognizer *scaleGes = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleImage:)]; [self addGestureRecognizer:pinchGestureRecognizer];
[self addGestureRecognizer:scaleGes];
// 移动手势
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)];
[panGestureRecognizer setMinimumNumberOfTouches:1];
[panGestureRecognizer setMaximumNumberOfTouches:1];
[self addGestureRecognizer:panGestureRecognizer];
//// 旋转
// UIRotationGestureRecognizer *rotateGes = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)];
// [self addGestureRecognizer:rotateGes];
//
//// 放大缩小
// UIPinchGestureRecognizer *scaleGes = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleImage:)];
// [self addGestureRecognizer:scaleGes];
//
//
//// 移动
// UIPanGestureRecognizer *moveGes = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveImage:)];
// [moveGes setMinimumNumberOfTouches:1];
// [moveGes setMaximumNumberOfTouches:1];
// [self addGestureRecognizer:moveGes];
// 长按 // 长按
UILongPressGestureRecognizer *longPressGR = UILongPressGestureRecognizer *longPressGR =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress2:)]; [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress2:)];
...@@ -59,14 +78,37 @@ ...@@ -59,14 +78,37 @@
longPressGR.minimumPressDuration = 0.5; longPressGR.minimumPressDuration = 0.5;
[self addGestureRecognizer:longPressGR]; [self addGestureRecognizer:longPressGR];
// 移动 }
UIPanGestureRecognizer *moveGes = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveImage:)]; // 处理旋转手势
[moveGes setMinimumNumberOfTouches:1]; - (void) rotateView:(UIRotationGestureRecognizer *)rotationGestureRecognizer
[moveGes setMaximumNumberOfTouches:1]; {
[self addGestureRecognizer:moveGes]; UIView *view = rotationGestureRecognizer.view;
if (rotationGestureRecognizer.state == UIGestureRecognizerStateBegan || rotationGestureRecognizer.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformRotate(view.transform, rotationGestureRecognizer.rotation);
[rotationGestureRecognizer setRotation:0];
}
}
// 处理缩放手势
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
UIView *view = pinchGestureRecognizer.view;
if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
pinchGestureRecognizer.scale = 1;
}
} }
// 处理拖拉手势
- (void) panView:(UIPanGestureRecognizer *)panGestureRecognizer
{
UIView *view = panGestureRecognizer.view;
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan || panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [panGestureRecognizer translationInView:view.superview];
[view setCenter:(CGPoint){view.center.x + translation.x, view.center.y + translation.y}];
[panGestureRecognizer setTranslation:CGPointZero inView:view.superview];
}
}
float _lastTransX = 0.0, _lastTransY = 0.0; float _lastTransX = 0.0, _lastTransY = 0.0;
- (void)moveImage:(UIPanGestureRecognizer *)sender - (void)moveImage:(UIPanGestureRecognizer *)sender
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment