双容器视图动画 iOS
Dual Container View Animation iOS
所以我有一个 ViewController,它有两个容器视图。最上面的是主要内容。底部是一个横幅,在某些事件中会 hide/show。
在事件发生之前,底部的位置位于选项卡栏下方。
事件发生时,主视图的框架会缩小,横幅的框架会重新定位,这样它就会 'slide' 出现在视图中并变得可用。
我遇到的问题是,除非我在故事板中调整主视图的大小(这不是我想要的),否则我在代码中所做的任何调整都会显示横幅,但横幅不会响应触摸. (在情节提要中调整大小,它确实有响应。)它前面似乎有其他视图正在拦截触摸,但是什么,我该如何解决?
主视图控制器:
func hideBanner() {
bannerViewController?.toggleBannerDisplay(show: false)
contentTableViewController?.toggleBannerDisplay(show: false)
}
func showBanner() {
bannerViewController?.toggleBannerDisplay(show: true)
contentTableViewController?.toggleBannerDisplay(show: true)
}
内容table视图控制器:
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
我试图为嵌入式视图控制器的视图设置动画,这确实使所有内容都出现并就位,但容器视图仍然隐藏在顶部。
我为容器视图设置了动画,现在一切正常。
所以我有一个 ViewController,它有两个容器视图。最上面的是主要内容。底部是一个横幅,在某些事件中会 hide/show。
在事件发生之前,底部的位置位于选项卡栏下方。
事件发生时,主视图的框架会缩小,横幅的框架会重新定位,这样它就会 'slide' 出现在视图中并变得可用。
我遇到的问题是,除非我在故事板中调整主视图的大小(这不是我想要的),否则我在代码中所做的任何调整都会显示横幅,但横幅不会响应触摸. (在情节提要中调整大小,它确实有响应。)它前面似乎有其他视图正在拦截触摸,但是什么,我该如何解决?
主视图控制器:
func hideBanner() {
bannerViewController?.toggleBannerDisplay(show: false)
contentTableViewController?.toggleBannerDisplay(show: false)
}
func showBanner() {
bannerViewController?.toggleBannerDisplay(show: true)
contentTableViewController?.toggleBannerDisplay(show: true)
}
内容table视图控制器:
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
我试图为嵌入式视图控制器的视图设置动画,这确实使所有内容都出现并就位,但容器视图仍然隐藏在顶部。
我为容器视图设置了动画,现在一切正常。