Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.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 如何通过向下拖动(平移)关闭UITableViewController_Ios_Swift_Uipangesturerecognizer - Fatal编程技术网

Ios 如何通过向下拖动(平移)关闭UITableViewController

Ios 如何通过向下拖动(平移)关闭UITableViewController,ios,swift,uipangesturerecognizer,Ios,Swift,Uipangesturerecognizer,我正在制作一个iOS应用程序 现在我坚持做以下事情 详细信息屏幕作为模式屏幕弹出 用户希望通过像推特的照片屏幕一样向下拖动来关闭模式窗口 我试图通过引用 我的代码如下所示。 它使tableView移动到奇怪的方向,然后关闭模式 var firstX: CGFloat = 0 var firstY: CGFloat = 0 var finalX: CGFloat = 0 var finalY: CGFloat = 0 override func viewDidLoad() { sup

我正在制作一个iOS应用程序

现在我坚持做以下事情

  • 详细信息屏幕作为模式屏幕弹出
  • 用户希望通过像推特的照片屏幕一样向下拖动来关闭模式窗口
我试图通过引用

我的代码如下所示。 它使tableView移动到奇怪的方向,然后关闭模式

var firstX: CGFloat = 0
var firstY: CGFloat = 0
var finalX: CGFloat = 0
var finalY: CGFloat = 0

override func viewDidLoad() {
    super.viewDidLoad()
    let recognizer : UIPanGestureRecognizer = UIPanGestureRecognizer(target: self, action: "move:")
    recognizer.minimumNumberOfTouches = 1
    recognizer.maximumNumberOfTouches = 1
    self.tableView.addGestureRecognizer(recognizer)
}

func move(sender : UIPanGestureRecognizer) {
    print("move")

    self.view.bringSubviewToFront(tableView)
    var translatedPoint : CGPoint = sender.translationInView(self.view)
    if sender.state == UIGestureRecognizerState.Began {
        firstX = 0 // (sender.view?.center.x)!
        firstY = (tableView?.center.y)!
    }
    translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY)
    tableView?.center = translatedPoint

    if sender.state == UIGestureRecognizerState.Ended {
        let velocityY = 0.2 * sender.velocityInView(self.view).y
        finalX = firstX //translatedPoint.x + velocityX
        finalY = translatedPoint.y + velocityY

        if (UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)) {

            if finalY < 0 {
                finalY = 0
            } else if finalY > 1024 {
                finalY = 1024
            }

        } else {

            if finalY < 0 {
                finalY = 0
            } else if finalY > 768 {
                finalY = 1024
            }
        }

        let animationDuration = ( abs(velocityY) * 0.0002 ) + 0.2

        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationDuration(Double(animationDuration))
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseOut)
        UIView.setAnimationDelegate(self)
        UIView.setAnimationDidStopSelector("animationDidFinish")
        self.view.center = CGPointMake(finalX, finalY)
        UIView.commitAnimations()


    }
}

func animationDidFinish() {
    print("animationDidFinish")
    if finalY > 50 {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

}
var firstX:CGFloat=0
变量firstY:CGFloat=0
变量finalX:CGFloat=0
最终变量:CGFloat=0
重写func viewDidLoad(){
super.viewDidLoad()
let recognizer:uipangestureerecognizer=uipangestureerecognizer(目标:self,操作:“移动:”)
识别器.MinimumNumberOfTouchs=1
识别器.MaximumNumberOfTouchs=1
self.tableView.addgestureRecognitor(识别器)
}
func移动(发送方:UIPangestureRecognitor){
打印(“移动”)
self.view.bringSubview到前台(tableView)
var translatedPoint:CGPoint=sender.translationView(self.view)
如果sender.state==UIGestureRecognitizerState.Start{
firstX=0/(sender.view?.center.x)!
firstY=(tableView?.center.y)!
}
translatedPoint=CGPointMake(firstX+translatedPoint.x,firstY)
tableView?中心=平移点
如果sender.state==UIGestureRecognitizerState.Ended{
设velocityY=0.2*sender.velocityView(self.view).y
finalX=firstX//translatedPoint.x+velocityX
finalY=translatedPoint.y+velocityY
if(UIDeviceOrientationSportRait(UIDevice.currentDevice().orientation)){
如果最终<0{
最终=0
}否则,如果最终>1024{
最终=1024
}
}否则{
如果最终<0{
最终=0
}否则,如果最终>768{
最终=1024
}
}
设animationDuration=(绝对速度)*0.0002)+0.2
UIView.beginAnimations(无,上下文:无)
UIView.setAnimationDuration(双精度(animationDuration))
UIView.setAnimationCurve(UIViewAnimationCurve.EaseOut)
UIView.setAnimationDelegate(自身)
UIView.setAnimationDidStopSelector(“animationDidFinish”)
self.view.center=CGPointMake(finalX,finalY)
UIView.commitAnimations()
}
}
func animationdidfish(){
打印(“动画完成”)
如果最终超过50{
self.dismissViewControllerAnimated(真,完成:无)
}
}
有人给我指出正确的方向吗?
提前感谢。

您需要创建自定义模态动画。您应该阅读本节的内容

特别是其中有一部分,但你可能需要阅读更多的内容才能理解

简而言之,您必须创建的实现,并将其分配给正在呈现的视图控制器的转换委托。的工作是将许多其他对象提供给
UIKit
,这些对象处理自定义动画(以及可选的显示),以显示和解除视图控制器


除了的实现之外,您还必须创建和的实现。这些对象最终将是执行相关动画的对象,它们是由您的实现出售给
UIKit
的对象。

我没有任何可以发布的对象。几乎可以肯定的是,文档和/或WWDC会话中有使用这些API的示例。