如何在滑动手势ios后停止动画

时间:2015-06-06 04:40:09

标签: ios swift uiviewanimation swipe-gesture

 func swipedirections(sender : UIView)
{
    var swipeRight = UISwipeGestureRecognizer(target: self, action: Selector("swipedIt:"))
    swipeRight.direction = UISwipeGestureRecognizerDirection.Right
    sender.addGestureRecognizer(swipeRight)

    var left = UISwipeGestureRecognizer(target: self, action: Selector("swipedIt:"))
    left.direction = UISwipeGestureRecognizerDirection.Left
    sender.addGestureRecognizer(left)


    //self.nextView(UISwipeGestureRecognizer())


}

func swipedIt(sender: UISwipeGestureRecognizer)
{

    UIView.animateWithDuration(0.5) { () -> Void in

    if (sender.direction == UISwipeGestureRecognizerDirection.Left)
    {

        var labelPosition = CGPointMake(self.viewSlide.frame.origin.x - 400.0, self.viewSlide.frame.origin.y);

        self.viewSlide.frame = CGRectMake( labelPosition.x , labelPosition.y , self.viewSlide.frame.size.width, self.viewSlide.frame.size.height)

    }
        if (sender.direction == UISwipeGestureRecognizerDirection.Right)
        {
            var labelPosition = CGPointMake(self.viewSlide.frame.origin.x + 400.0, self.viewSlide.frame.origin.y);

            self.viewSlide.frame = CGRectMake( labelPosition.x , labelPosition.y , self.viewSlide.frame.size.width, self.viewSlide.frame.size.height)
        }

    }

    self.nextView(sender)

}

func nextView(sender: UISwipeGestureRecognizer)
{

    self.viewSlide.layer.removeAllAnimations()

    self.viewSlide.frame = actualPer}

当我向右或向左滑动时,它很顺利。但刷卡后,我希望同样的视图再次回来。它是在动画中回来但我想要一个视图返回恒定但不是在移动的动作0.0持续时间。

请帮帮我

0 个答案:

没有答案