Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用UIPangestureRecognitor移动时,图片始终移回原点_Ios_Xcode_Uipangesturerecognizer - Fatal编程技术网

Ios 使用UIPangestureRecognitor移动时,图片始终移回原点

Ios 使用UIPangestureRecognitor移动时,图片始终移回原点,ios,xcode,uipangesturerecognizer,Ios,Xcode,Uipangesturerecognizer,我尝试以编程方式实现平移手势,但尝试时,uiview总是在移动过程中移回superview中的原点。所以事实上,它从原点向前跳到新的位置。 有人知道问题出在哪里吗 代码: 我认为您的翻译与自动布局约束冲突。 从“关于变换和自动布局”中查看 - (void)setGesture { self.userInteractionEnabled = YES; UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecogniz

我尝试以编程方式实现平移手势,但尝试时,uiview总是在移动过程中移回superview中的原点。所以事实上,它从原点向前跳到新的位置。 有人知道问题出在哪里吗

代码:


我认为您的翻译与自动布局约束冲突。
从“关于变换和自动布局”中查看

- (void)setGesture
{
    self.userInteractionEnabled = YES;
        UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(detectPan:)];
        self.gestureRecognizers = @[panRecognizer];


}

- (void) detectPan:(UIPanGestureRecognizer *) penGes
{
    if ((penGes.state == UIGestureRecognizerStateChanged) ||
        (penGes.state == UIGestureRecognizerStateEnded))
    {

        CGPoint translation = [penGes translationInView:self.superview];
        self.center = CGPointMake(self.lastLocation.x + translation.x,
                              self.lastLocation.y + translation.y);

       [penGes setTranslation:CGPointZero inView:self];
    }
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Promote the touched view
    [self.superview bringSubviewToFront:self];

    // Remember original location
    self.lastLocation = self.center;
}