【问题标题】:Dual Container View Animation iOS双容器视图动画 iOS
【发布时间】:2018-05-23 00:07:06
【问题描述】:

所以我有一个 ViewController,它有两个容器视图。最上面的是主要内容。底部是一个横幅,将在某些事件中隐藏/显示。

底部的位置在事件发生之前一直位于标签栏下方。

当事件发生时,主视图的框架会缩小,横幅的框架会重新定位,使其看起来“滑入”视图并变为可用。

我遇到的问题是,除非我在情节提要中调整主视图的大小(这不是我想要的),否则我在代码中所做的任何调整都会显示横幅,但横幅不会响应触摸。 (在情节提要中调整大小,它确实会响应。)它前面似乎有一些其他视图正在拦截触摸,但是什么,以及如何修复它?

主视图控制器:

func hideBanner() {
    bannerViewController?.toggleBannerDisplay(show: false)
    contentTableViewController?.toggleBannerDisplay(show: false)
}
func showBanner() {
    bannerViewController?.toggleBannerDisplay(show: true)
    contentTableViewController?.toggleBannerDisplay(show: true)
}

内容表视图控制器:

func toggleBannerDisplay(show: Bool) {
    let tableView = self.view as! UITableView

    UIView.animate(withDuration: 0.5, animations: {
        if self.cancelApplyShowing == false && show == true {
            let frame = tableView.frame
            let newFrame = CGRect(x:frame.origin.x , y: frame.origin.y, width: frame.size.width, height: frame.size.height - 48)
            tableView.contentSize = newFrame.size
            tableView.frame = newFrame
            self.cancelApplyShowing = true
        } else if self.cancelApplyShowing == true && show == false {
            let frame = tableView.frame
            let newFrame = CGRect(x:frame.origin.x , y: frame.origin.y, width: frame.size.width, height: frame.size.height + 48)
            tableView.contentSize = newFrame.size
            tableView.frame = newFrame
            self.cancelApplyShowing = false
        }
    })
}

横幅:

func toggleBannerDisplay(show: Bool) {
    UIView.animate(withDuration: 0.5, animations: {
        if self.cancelApplyShowing == false && show == true {
            let frame = self.view.frame
            let newFrame = CGRect(x: frame.origin.x, y: frame.origin.y - 48, width: frame.size.width, height: frame.size.height)
            self.view.frame = newFrame
            self.cancelApplyShowing = true
        } else if self.cancelApplyShowing == true && show == false {
            self.view.frame.origin.y += 48
            self.cancelApplyShowing = false
        }
    })
}

由于某种原因,如果我调整主视图的大小,隐藏视图会变得响应(当然是在动画之后)。

Vimeo 视频:https://vimeo.com/246496442

【问题讨论】:

    标签: ios cocoa-touch core-animation


    【解决方案1】:

    我试图为嵌入式视图控制器的视图设置动画,这确实将所有内容都显示到位,但容器视图仍然不可见地位于顶部。

    对容器视图进行了动画处理,现在一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-09
      • 1970-01-01
      相关资源
      最近更新 更多