如何从右到左移动另一个视图上的一个视图

时间:2013-05-25 08:15:15

标签: ios objective-c touch

我在我的应用程序中创建显示菜单,从左侧打开它(当我从左向右拖动时,首页从左向右移动)现在我尝试更改此但我不能。请指导我如何更改此菜单并将其放在右侧并打开此侧(从右向左拖动)。

我的朋友这是我的代码:

#pragma mark UITouch Logic

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    if (_slideNavigationControllerState == kSlideNavigationControllerStateDrilledDown ||
        _slideNavigationControllerState == kSlideNavigationControllerStateSearching)
        return;

    UITouch *touch = [touches anyObject];
    _startingDragPoint = [touch locationInView:self.view];

    if ((CGRectContainsPoint(_slideNavigationController.view.frame, _startingDragPoint))
      && _slideNavigationControllerState == kSlideNavigationControllerStatePeeking) {

        _slideNavigationControllerState = kSlideNavigationControllerStateDragging;
        _startingDragTransformTx = _slideNavigationController.view.transform.tx;
    }

    // we only trigger a swipe if either navigationBarOnly is deactivated
    // or we swiped in the navigationBar
    if (!kSVCSwipeNavigationBarOnly || _startingDragPoint.y <= 44.0f) {

        _slideNavigationControllerState = kSlideNavigationControllerStateDragging;
        _startingDragTransformTx = _slideNavigationController.view.transform.tx;

    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    if (_slideNavigationControllerState != kSlideNavigationControllerStateDragging)
        return;

    UITouch *touch = [touches anyObject];

    CGPoint location = [touch locationInView:self.view];

    [UIView animateWithDuration:0.05f 
                          delay:0.0f
                         options:UIViewAnimationOptionCurveLinear |
                                 UIViewAnimationOptionBeginFromCurrentState 
        animations:^{

        _slideNavigationController.view.transform = CGAffineTransformMakeTranslation(
             MAX(_startingDragTransformTx + (location.x - _startingDragPoint.x),
              0.0f),0.0f);

        NSLog(@"%d",_slideNavigationController.view.transform);

    } completion:^(BOOL finished) {

    }];                
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    if (_slideNavigationControllerState == kSlideNavigationControllerStateDragging) {
        UITouch *touch = [touches anyObject];
        CGPoint endPoint = [touch locationInView:self.view];

        // Check in which direction we were dragging
        if (endPoint.x < _startingDragPoint.x) {
            if (_slideNavigationController.view.transform.tx <= kSVCRightAnchorX) {
                [self slideInSlideNavigationControllerView];
            } else {
                [self slideOutSlideNavigationControllerView];
            }
        } else {
            if (_slideNavigationController.view.transform.tx >= kSVCLeftAnchorX) {
                [self slideOutSlideNavigationControllerView];
            } else {
                [self slideInSlideNavigationControllerView];
            }
        }
    }

}

1 个答案:

答案 0 :(得分:2)

你想要从右到左移动视图。使用滑动手势识别来执行此操作的最佳方法。点击此链接(swipegesture)