ios - UIPageViewController 的 subview 没有动画 subview ? swift 4

标签 ios swift uiview uipagecontrol

经过许多令人沮丧的时间和一个不满意的客户,我决定来这里。

这是我的 pageController 的第一个 subview 类中的 viewDidAppear

 override func viewDidAppear(_ animated: Bool) {
       print("hello")
     self.view.layoutIfNeeded()
  self.averageWorkSessions.shapeLayer.strokeEnd = 0
    UIView.animate(withDuration: 0.5) {
        let average = CGFloat(self.averageWorkSessions.average / 10)
        self.averageWorkSessions.shapeLayer.strokeEnd = average
        if !(average > 0.0){
            self.averageWorkSessions.Title.text = "N/A"
        }
        self.view.layoutIfNeeded()
    }
}

考虑一下

averageWorkSessions 是一个带有自定义组件的自定义 View ,但它仍然是 UIView 的子类

这是无论如何都可能与此问题相关的页面 Controller 的一部分

  lazy var subViewControllers: [UIViewController] = {

    return [

    UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Stats1") as! StatisticsViewController ,
     UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Stats2") as! Statistics2ViewController ,
       UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Stats3") as! Statistics3ViewController
    ]

}()

override func viewDidLoad() {
    super.viewDidLoad()
    self.delegate = self
    self.dataSource = self
    setViewControllers([subViewControllers[0]], direction: .forward , animated: true, completion: nil)
    self.view.layoutIfNeeded()
}

精简版

为什么动画不正确?打印“你好”完全符合预期……为什么不是我的动画?

最佳答案

我认为问题在于您正在 UIView.animate() 中设置 self.averageWorkSessions.shapeLayer.strokeEnd

self.view.layoutIfNeeded() 应该在 UIView.animate() 中,但是设置常量不应该。

关于ios - UIPageViewController 的 subview 没有动画 subview ? swift 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48934465/

相关文章:

ios - 在两个 UiViewController 和 UIView 之间实现拖动和滑动过渡?

ios - 使用 CollectionView 删除 Core Data 中的记录

ios - 使用swift继承两个类

swift - 根据条件选择segue

swift - 在 Swift 中将 NSData 转换为整数

uitableview - 要捕获一切! - UITableView 上的 UIView 没有接收到点击

ios - Objective-C 用不同的 UIView 替换当前的 UIView

ios - 更改自定义 UIView 的 UILabel 文本不起作用

ios - UITabBar在iOS 7中的行为很奇怪,如何解决?

java - 如何强制用户更新应用?