OGeek|极客世界-中国程序员成长平台

标题: ios - 显示 View 后立即添加 subview [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:09
标题: ios - 显示 View 后立即添加 subview

我有 2 个 View A 和 B。 在 View A

presentViewController(viewB, animation: true) {
  NSNotificationCenter.defautCenter.postNotificationName("addButton")
}

在 View B: var masterView:UIView!

func addButton(notification: NSNotification){
    var button:UIButton!
    button.frame = masterView.caculator // set frame for button
    self.addSubview(button)
}

当 View B 在模拟器上完成动画时(从底部开始)。延迟 0.3 秒后添加的按钮。

跟随一些文档,当动画完成时,方法 viewDidAppear 被调用。我试过这种方式。但正如我所见,动画完成 0.3 秒后添加的按钮

如何在动画完成后立即添加按钮? 谢谢!



Best Answer-推荐答案


我已经解决了。因为在viewDidAppear中,这个方法是在所有Layout加载完毕的时候调用的。 所以我们需要在 LayoutSubview 方法中实现 add my button。

关于ios - 显示 View 后立即添加 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38711203/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4