ios - 禁用 scrollViewDidScroll:滚动 UICollectionView 时 - iOS
问题描述
我已经实现了 scrollViewDidScroll: 在我的视图控制器中,当我上下滚动视图时会产生一些动画。
但是,当我在 viewcontroller(水平)内滚动我的 collectionview 时,它会弄乱我在 scrollViewDidScroll 内的动画:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
newAlpha = 1 - scrollView.contentOffset.y / 200;
self.introImageView.alpha = newAlpha;
//... -> prevent scrolling when collectionview is scrolled
}
如何防止调用 scrollViewDidScroll: 水平滚动我的 collectionview 时?
解决方案
最好的方法不是禁用委托方法,而是确保仅在滚动视图调用该代码时才调用该代码。这是一个例子
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.myScrollView) {
newAlpha = 1 - scrollView.contentOffset.y / 200;
self.introImageView.alpha = newAlpha;
} else {
//collectionView would fall here
}
}
推荐阅读
- fortran - 如何在运行开始期间在各种选项中为子程序选择所需的代码
- c - 如何让线程崩溃不会导致进程崩溃?
- qt - 替换 qhash 值 no operator found 采用右手操作数类型
- elasticsearch - ElasticSearch 搜索查询计数
- ios - PHPhotoLibrary.requestAuthorization(for:, handler:) 不调用处理程序块
- lua - 修复脚本
- reactjs - React 路由与 MVC 路由,这里发生了什么?
- python - 我永远无法返回的循环
- javascript - 如何在 Vue 应用程序中实时显示 DynamoDB 数据中的数据更改?
- r - 如何在 R 中将 unicode 箭头作为字符变量?