Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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
Swift 根据滚动视图更改视图的高度和宽度使用自动布局水平滚动视图_Swift_Swift3_Uiscrollview_Ios Autolayout - Fatal编程技术网

Swift 根据滚动视图更改视图的高度和宽度使用自动布局水平滚动视图

Swift 根据滚动视图更改视图的高度和宽度使用自动布局水平滚动视图,swift,swift3,uiscrollview,ios-autolayout,Swift,Swift3,Uiscrollview,Ios Autolayout,容器视图层次结构:- 容器视图 滚动视图 左视图 视图中心 视图权限 浮动底视图 我需要根据scrollview水平滚动来更改浮动底部视图的height和width约束 初始出口:- @IBOutlet weak var constantFloatingBottomViewWidth: NSLayoutConstraint! // 300 @IBOutlet weak var constantFloatingBottomViewHeight: NSLayoutConstraint!

容器视图层次结构:-

  • 容器视图
    • 滚动视图
      • 左视图
      • 视图中心
      • 视图权限
    • 浮动底视图
我需要根据
scrollview
水平滚动来更改浮动底部视图的
height
width
约束

初始出口:-

@IBOutlet weak var constantFloatingBottomViewWidth: NSLayoutConstraint! // 300
@IBOutlet weak var constantFloatingBottomViewHeight: NSLayoutConstraint! // 70

override func viewWillAppear(_ animated: Bool) {
         self.scrollView.contentOffset.x = self.view.bounds.width
         // view center in scrollview
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
     if scrollView.contentOffset.x < self.view.bounds.width {
        // when scrollview move view center to view left, constantFloatingBottomViewWidth and height goes to down at some point  
     }
     else if scrollView.contentOffset.x > self.view.bounds.width {
       // when scrollview move view left to view center, constantFloatingBottomViewWidth & height goes up to same point range while it down and back to original constantFloatingBottomViewWidth and height
     }
}

我认为你需要像这样制作按钮动画

对于这一点,您无需做什么,只需添加动画按钮一样遵循 在viewDidLoad中调用SetupButtonImation

 func setupButtonAnimation()
        {
            let animation = CABasicAnimation.init(keyPath: "transform.scale")
            animation.fromValue = 1.0
            animation.toValue = 0.45
            animation.duration = 1.0
            //Set the speed of the layer to 0 so it doesn't animate until we tell it to
            self.btn1.layer.speed = 0.0;
            self.btn1.layer.add(animation, forKey: "transform");
        }
        func scrollViewDidScroll(_ scrollView: UIScrollView)
        {
            let screenSize = self.view.bounds.size
            if let btn =  self.btn1
            {
                var factor:CGFloat = 1.0
                factor = scrollView.contentOffset.x / screenSize.width
                if factor > 1
                {
                        factor = 2 - factor
                }
                print(factor)
                //This will change the size
                let timeOffset = CFTimeInterval(1-factor)
                btn.layer.timeOffset = timeOffset
               }
        }

我认为你需要像这样制作按钮动画

对于这一点,您无需做什么,只需添加动画按钮一样遵循 在viewDidLoad中调用SetupButtonImation

 func setupButtonAnimation()
        {
            let animation = CABasicAnimation.init(keyPath: "transform.scale")
            animation.fromValue = 1.0
            animation.toValue = 0.45
            animation.duration = 1.0
            //Set the speed of the layer to 0 so it doesn't animate until we tell it to
            self.btn1.layer.speed = 0.0;
            self.btn1.layer.add(animation, forKey: "transform");
        }
        func scrollViewDidScroll(_ scrollView: UIScrollView)
        {
            let screenSize = self.view.bounds.size
            if let btn =  self.btn1
            {
                var factor:CGFloat = 1.0
                factor = scrollView.contentOffset.x / screenSize.width
                if factor > 1
                {
                        factor = 2 - factor
                }
                print(factor)
                //This will change the size
                let timeOffset = CFTimeInterval(1-factor)
                btn.layer.timeOffset = timeOffset
               }
        }

您想增加浮动底视图的大小吗?是的,它的高度和宽度限制可以根据scrollview水平滚动并返回到标识。@HussainShabbir您知道吗?我该如何解决这个问题。如果我理解正确,您只想在水平向右或向左滚动时显示与scrollview相关的底部按钮???@HussainShabbir,是的,就像snapchat相机按钮动画一样。您想增加浮动底部视图的大小吗?是的,它的高度和宽度限制根据scrollview水平滚动并返回到标识。@HussainShabbir你知道吗?我如何解决这个问题。如果我理解正确,你只想在水平向右或向左滚动时,显示与scrollview相关的底部按钮???@HussainShabbir,是的,就像snapchat相机按钮动画一样。