实施了iOS 8 Custom Keyboard: Changing the Height中描述的类似方法,我有两个主要问题,我似乎无法弄清楚。
1)当发生旋转时,会出现非常明显的跳跃。键盘以其当前高度旋转,然后仅在旋转完成后才突然跳转到新的高度。
2)在旋转完成之前,键盘的内容似乎不会被绘制。当尝试使用各种可用的回调时,这会导致一系列问题。例如,我试图将我的scrollView(位于键盘底部)(类似于旧的表情符号键盘)的contentSize高度设置为与我的scrollView相同的高度。然而,
scrollView.contentSize = scrollView.frame.size.height
不起作用,因为scrollView(也不是它的封闭视图 - 也尝试过)还没有达到它的最终界限。我通过在键盘完全加载后检查边界来验证这一点 - 然后只有scrollView返回正确的高度值。
当我尝试设置我的collectionView(包括键盘主体)内容的大小时,会发生同样的事情:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let heightPortrait: CGFloat = 0.8
let heightLandscape: CGFloat = 0.8
var collectionViewHeight = collectionView.bounds.size.height
var portrait = collectionViewHeight * heightPortrait
var landscape = collectionViewHeight * heightLandscape
var newDimensions: CGFloat
newDimensions = UIScreen.mainScreen().bounds.size.width < UIScreen.mainScreen().bounds.size.height ? portrait : landscape
return CGSize(width: newDimensions, height: newDimensions)
}
我已经实现了viewWillTransitionToSize,因此每个对象都会在轮换时更新,但是当它被调用时,边界再次尚未设置:
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
self.setKeyboardHeight() // Change the keyboard height from its default setting.
self.buildScrollView() // Populate the scrollView and set contentSize as well as cell attributes.
println("Before: \(self.view4.frame.size.height)") // Is the same as 'After' (see a few lines below), also swapping out view4 (the scrollView's superview) for scrollView doesn't change anything.
coordinator.animateAlongsideTransition(nil, completion: { context in
self.collectionView?.collectionViewLayout.invalidateLayout()
println("After: \(self.view4.frame.size.height)")
})
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
}
我已经过了很长时间,但是如果有人能帮助我解决这个问题,我将永远感激不尽。非常感谢你的帮助,随时你可以回答/解决这个问题!!