【发布时间】: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