Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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 Swift-插入UIView并将其设置为UIScrollView内的XY坐标的动画_Ios_Swift_Uiscrollview_Autolayout_Transform - Fatal编程技术网

Ios Swift-插入UIView并将其设置为UIScrollView内的XY坐标的动画

Ios Swift-插入UIView并将其设置为UIScrollView内的XY坐标的动画,ios,swift,uiscrollview,autolayout,transform,Ios,Swift,Uiscrollview,Autolayout,Transform,我正在尝试设置插入子视图的动画,从按下的网格编号(编号1)到顶行(位置B-请参见图) 我已经成功地移动了UIView的xy,但我似乎无法找到如何在不使用CGPoints/cgfloat的情况下将其从A移动到B 我已尝试将cgfalot指定给positionAViewbounds.origin.x&positionAViewbounds.origin.y,但它仅相对于superview而不是整个窗口视图移动 以下是我目前的代码: UIView.animateWithDuration

我正在尝试设置插入子视图的动画,从按下的网格编号(编号1)到顶行(位置B-请参见图)

我已经成功地移动了UIView的xy,但我似乎无法找到如何在不使用CGPoints/cgfloat的情况下将其从A移动到B

我已尝试将cgfalot指定给positionAViewbounds.origin.x&positionAViewbounds.origin.y,但它仅相对于superview而不是整个窗口视图移动

以下是我目前的代码:

        UIView.animateWithDuration(
         0.350, delay: 0, usingSpringWithDamping: 0.850, initialSpringVelocity: 10.0, options: [], animations: {


            self.yellowSquare.transform = CGAffineTransformMakeTranslation(50, -50)


            }, completion:nil)
// Inserting Yellow UIView
func createYellowSquare() {
    self.yellowSquare.frame = ballEmptyR1B1.frame //Define size of UiView
    self.yellowSquare.backgroundColor = colorYellow //Set colors
    self.numberGrid1.insertSubview(yellowSquare, aboveSubview: numberGrid1) //Insert Yellow Square
}


// Animate the ball pressed number to empty slot
func animateBalls() {

UIView.animateWithDuration(
    0.200, delay: 0, usingSpringWithDamping: 0.950, initialSpringVelocity: 5.0, options: [], animations: {

        //Convert the center points 
        let yellowUIViewCoordinates = self.yellowSquare.convertPoint(self.yellowSquare.center, toView: self.ballEmptyR1B1)
        print("Yellow coord = \(yellowUIViewCoordinates.x)")
        print("Yellow coord = \(yellowUIViewCoordinates.y)")

        //CGAffine Transform to new x y co-ordinates
        self.yellowSquare.transform = CGAffineTransformMakeTranslation(yellowUIViewCoordinates.x - 24, yellowUIViewCoordinates.y - 18)//Move to new center point

    }, completion: { _ in
            self.yellowSquare.removeFromSuperview() // Remove YellowUIView after animation is complete

            self.ballEmptyR1B1.transform = CGAffineTransformMakeScale(0.5, 0.5); //Scale UIView 0.5
            self.selectedNumberR1B1.transform = CGAffineTransformMakeScale(0.5, 0.5); //Scale UIView 0.5

            UIView.animateWithDuration(
                0.450, delay: 0.0, usingSpringWithDamping: 0.450, initialSpringVelocity: 15.0, options: [], animations: {
                    self.ballEmptyR1B1.transform = CGAffineTransformMakeScale(1.0, 1.0); //Scale UIView 1.0
                    self.selectedNumberR1B1.transform = CGAffineTransformMakeScale(1.0, 1.0); //Scale UIView 1.0
                },  completion:nil)
        }
        )

更新:

所以我通过使用“convertPoint”使它工作起来 我唯一想不出的问题是,只有当我第二次按下UIButton时,它才起作用

首次按下时,坐标为:

黄色坐标=-16.5

黄坐标=288.0

第二次按压时,坐标为:

黄色坐标=24.0

黄坐标=18.0

以下是我目前的代码:

        UIView.animateWithDuration(
         0.350, delay: 0, usingSpringWithDamping: 0.850, initialSpringVelocity: 10.0, options: [], animations: {


            self.yellowSquare.transform = CGAffineTransformMakeTranslation(50, -50)


            }, completion:nil)
// Inserting Yellow UIView
func createYellowSquare() {
    self.yellowSquare.frame = ballEmptyR1B1.frame //Define size of UiView
    self.yellowSquare.backgroundColor = colorYellow //Set colors
    self.numberGrid1.insertSubview(yellowSquare, aboveSubview: numberGrid1) //Insert Yellow Square
}


// Animate the ball pressed number to empty slot
func animateBalls() {

UIView.animateWithDuration(
    0.200, delay: 0, usingSpringWithDamping: 0.950, initialSpringVelocity: 5.0, options: [], animations: {

        //Convert the center points 
        let yellowUIViewCoordinates = self.yellowSquare.convertPoint(self.yellowSquare.center, toView: self.ballEmptyR1B1)
        print("Yellow coord = \(yellowUIViewCoordinates.x)")
        print("Yellow coord = \(yellowUIViewCoordinates.y)")

        //CGAffine Transform to new x y co-ordinates
        self.yellowSquare.transform = CGAffineTransformMakeTranslation(yellowUIViewCoordinates.x - 24, yellowUIViewCoordinates.y - 18)//Move to new center point

    }, completion: { _ in
            self.yellowSquare.removeFromSuperview() // Remove YellowUIView after animation is complete

            self.ballEmptyR1B1.transform = CGAffineTransformMakeScale(0.5, 0.5); //Scale UIView 0.5
            self.selectedNumberR1B1.transform = CGAffineTransformMakeScale(0.5, 0.5); //Scale UIView 0.5

            UIView.animateWithDuration(
                0.450, delay: 0.0, usingSpringWithDamping: 0.450, initialSpringVelocity: 15.0, options: [], animations: {
                    self.ballEmptyR1B1.transform = CGAffineTransformMakeScale(1.0, 1.0); //Scale UIView 1.0
                    self.selectedNumberR1B1.transform = CGAffineTransformMakeScale(1.0, 1.0); //Scale UIView 1.0
                },  completion:nil)
        }
        )
下面是slo mo中的gif记录,为我所指的内容提供更好的上下文:


在scrollView中,您想为两个有约束的按钮设置动画是吗?当您按“1”(带红色虚线边框)时:黄色UIView被创建并插入固定视图中“1”的顶部,然后应用“UIView.animateWithDuration”在新创建的YellowUIView上,我想告诉YellowUIView在不指定相对整数XY坐标的情况下,从创建点移动/设置动画到scrollView中的坐标(位置B)