我使用以下方法分别滚动和旋转,每个似乎工作正常.我刚刚注意到,在做这两件事的同时我可以得到这个崩溃.因此,当我旋转设备并且在prepareLayout中计算新的布局属性时,似乎与事实有关,即连续滚动触发“invalIDateLayoutWithContext(invalIDContext)”(见下文).
想法?有没有办法在旋转期间将任何滚动响应置于保持状态(或忽略它们)?
旋转方法
在视图控制器中的vIEwWillLayoutSubvIEws中,我使整个布局无效
self.cal.collectionVIEwLayout.invalIDateLayout()
滚动方法
为了让我有一个“粘性”装饰视图(标题)我不会使整个布局无效,因为它会杀死性能,但请执行以下 *** 作.在布局类中,我重写了shouldInvalIDateLayoutForBoundsChange
overrIDe func shouldInvalIDateLayoutForBoundsChange(newBounds: CGRect) -> Bool { let invalIDContext : UICollectionVIEwLayoutInvalIDationContext = self.invalIDationContextForBoundsChange(newBounds) // Keep header StickyinvalIDContext.invalIDatedecorationElementsOfKind(GCCalendarLayoutKind_Decorative1,atIndexPaths: [headerDecorativeIndexPath]) // Apply InvalIDation self.invalIDateLayoutWithContext(invalIDContext) // Return normal super return (just in case of future IOS upgrades) return super.shouldInvalIDateLayoutForBoundsChange(newBounds) }
请注意,我将装饰视图(标题)无效,而崩溃的错误是关于我的补充视图布局不同.
错误
解决方法 我不确定这是否足够但我会尝试沿着这些线尝试(集合视图是滚动视图):2015-10-30 07:14:30.181 test3_collectionvIEw[17086:3102132] *
Assertion failure in -[UICollectionVIEwData valIDateLayoutInRect:],
/buildroot/library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UICollectionVIEwData.m:408
2015-10-30 07:14:30.185 test3_collectionvIEw[17086:3102132] *
Terminating app due to uncaught exception
‘NSInternalinconsistencyException’,reason: ‘layout attributes for
supplementary item at index path ( {length =
2,path = 0 – 0}) changed from
index
path: ( {length = 2,path = 0 – 0}); element
kind: (Decorative1); frame = (0 1085.5; 320 16); zIndex = 1; to
index
path: ( {length = 2,path = 0 – 0}); element
kind: (Decorative1); frame = (0 853.5; 320 16); zIndex = 1; without
invalIDating the layout’
*** First throw call stack:
import CoreGraphicsclass myController: UIVIEwController,uiscrollviewdelegate { var myScrollVIEw = UIScrollVIEw() overrIDe func vIEwDIDLoad() { self.vIEw.addSubvIEw(myScrollVIEw) } // This will capture rotation events overrIDe func vIEwWillTransitionToSize(size: CGSize,withTransitionCoordinator coordinator: UIVIEwControllerTransitionCoordinator) { self.myScrollVIEw.scrollEnabled = false coordinator.notifyWhenInteractionEndsUsingBlock( {_ in self.myScrollVIEw.scrollEnabled = true} ) super.vIEwWillTransitionToSize(size,withTransitionCoordinator: coordinator) } func scrollVIEwDIDScroll(scrollVIEw: UIScrollVIEw) { // This will not ignore scroll but perhaps can help keePing things "tIDy" and "performant" during rotation. Not sure if myScrollVIEw.scrollEnabled == false { let offset = scrollVIEw.contentOffset myScrollVIEw.setContentOffset(offset,animated: false) } } }总结
以上是内存溢出为你收集整理的ios – 滚动whist旋转时UICollectionView崩溃(索引路径上的补充项的布局属性发生了变化而没有失效..)全部内容,希望文章能够帮你解决ios – 滚动whist旋转时UICollectionView崩溃(索引路径上的补充项的布局属性发生了变化而没有失效..)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)