0

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

我的朋友这是我的一段代码:

#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];
            }
        }
    }

}
4

1 回答 1

2

您想将视图从右向左移动。使用滑动手势识别的最佳方法。单击此链接(滑动手势)

于 2013-05-25T09:39:34.400 回答