代码之家  ›  专栏  ›  技术社区  ›  user

swift:移动uiview

  •  1
  • user  · 技术社区  · 6 年前

    我想为所有屏幕大小创建类似的动画。我有 UIView 在中间,想向右移动 uiview公司 屏幕应该是=10。

    怎么做?

    我的单屏代码(iphone 5s):

    UIView.animate(withDuration: 1.0, delay: 0.0, options: [], animations: {
    
       self.imageRevealed.center.x += 200
    
    })
    

    在这种情况下 uiview公司 屏幕=10。但对于其他屏幕,我应该用新的坐标来编写新代码。如何编写通用代码?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Mahendra    6 年前

    我想你需要图像视图和10px视图之间的尾随空格。

    let trailingSpace: CGFloat = 10
    UIView.animate(withDuration: 1.0, delay: 0.0, options: [], animations: {
    
       let screenSize = UIScreen.main.bounds.size
    
       let x = screenSize.width - self.imageRevealed.frame.size.width - trailingSpace
       let y = self.imageRevealed.frame.origin.y
    
       self.imageRevealed.frame = CGRect(x: x, y: y, width: self.imageRevealed.frame.size.width, height: self.imageRevealed.frame.size.height)
    
    })