【问题标题】:swipe UIView to the side and make him disappear - ios将 UIView 滑动到一边,让他消失 - ios
【发布时间】:2016-03-01 23:40:47
【问题描述】:

我想从中心向左或向右滑动一些 UIView,但在边缘之后我想让视图消失。滑动应该由握住手指的位置跟踪,并且在手指滑动视图到右侧或左侧后,视图应该飞到他滑到的一侧,但如果视图没有滑动,我希望他返回到他所在的位置。

我尝试在我的 UIView 上使用 UIPanGestureRecognizer

我的自定义 UIView 是 ArtistDetailsView

var panGestureRecognizer: UIPanGestureRecognizer!
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "handlePanFrom:")
self.artistDetailsView.addGestureRecognizer(panGestureRecognizer)

那是在 viewDidLoad() 函数中

func handlePanFrom(recognizer: UIPanGestureRecognizer) {
    let translation: CGPoint = recognizer.translationInView(recognizer.view)
    let velocity: CGPoint = recognizer.velocityInView(recognizer.view)
    print(translation)
    if recognizer.state == UIGestureRecognizerState.Began {

    }
    else if recognizer.state == UIGestureRecognizerState.Changed {
        //track the movement
    }

    else if recognizer.state == UIGestureRecognizerState.Ended {
        //animate to final position
    }
}

关于我的自定义视图 视图包围了整个屏幕 这意味着我的自定义视图和 ViewController 的重量是相等的。 当视图向左滑动时,视图的右侧应该在 ViewController 的左侧之后并消失,当视图向右滑动时,左侧应该在 ViewController 的右侧之后并消失。

问题是我不知道在 UIPanGestureRecognizer 的每个状态下该做什么。

如果有人能帮助我,我会很高兴的!

【问题讨论】:

    标签: ios iphone swift uiview uigesturerecognizer


    【解决方案1】:
    [secondViewController.view setFrame:rect]; //Where Rect is the current screen size 
    [UIView animateWithDuration:0.2 animations:^{
    // move this page to the right:
    [timeLinePaneController.view setFrame: swipeRightRect];
    } completion:^(BOOL finished) {
    
    
    }];
    

    这是向右滑动并加载背景页面的代码。

    【讨论】:

    • 没关系...我也懂objective-c,但我比较快。关于答案,这对我来说还不够。我需要滑动视图,例如向右滑动,并且我需要视图移动到我的手指移动它的位置,当我向右滑动视图时,我希望视图将在视图控制器的左侧之后飞行带动画。
    猜你喜欢
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 2014-07-28
    相关资源
    最近更新 更多