Stu*_*rtM 6 orientation uiimageview ios uipangesturerecognizer ios6
我有一个UIImageView可通过平移手势移动的东西.
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.photoMask addGestureRecognizer:pan];
Run Code Online (Sandbox Code Playgroud)
我想限制可以在屏幕上移动的区域.而不是用户能够将视图直接拖动到屏幕的一侧,我想限制它的某种边距.我怎样才能做到这一点?
另外,旋转后如何处理?
编辑---
#pragma mark - Gesture Recognizer
-(void)handlePan:(UIPanGestureRecognizer *)gesture {
NSLog(@"Pan Gesture");
gesture.view.center = [gesture locationInView:self.view];
}
Run Code Online (Sandbox Code Playgroud)
这是我目前处理平底锅的方法.我需要做的是继续按中心点移动图像视图,并在靠近屏幕边缘时将其移动限制为50.
一种可能的解决方案是在handlePan方法中,检查屏幕上点的位置,并且只有在您希望将其限制为的范围内时才提交更改.
对于前者
-(void) handlePan:(UIGestureRecognizer*)panGes{
CGPoint point = [panGes locationInView:self.view];
//Only allow movement up to within 100 pixels of the right bound of the screen
if (point.x < [UIScreen mainScreen].bounds.size.width - 100) {
CGRect newframe = CGRectMake(point.x, point.y, theImageView.frame.size.width, theImageView.frame.size.height);
theImageView.frame = newframe;
}
}
Run Code Online (Sandbox Code Playgroud)
我相信这也可以正确处理任何屏幕旋转
编辑
要通过框架的中心移动图像视图,handlePan方法可能如下所示.
-(void)handlePan:(UIPanGestureRecognizer *)gesture {
CGPoint point = [gesture locationInView:self.view];
//Only allow movement up to within 50 pixels of the bounds of the screen
//Ex. (IPhone 5)
CGRect boundsRect = CGRectMake(50, 50, 220, 448);
if (CGRectContainsPoint(boundsRect, point)) {
imgView.center = point;
}
}
Run Code Online (Sandbox Code Playgroud)
检查点是否在您想要的范围内,如果是,请将图像视图框的中心设置为该点.
| 归档时间: |
|
| 查看次数: |
15883 次 |
| 最近记录: |