iOS 运行时ScrollView上出现空白空间-解决方案

iOS7 中的UIViewControllers设置了automaticallyAdjustsScrollViewInsets。如果是YES,scrollview会根据status bar, navigation bar以及tool bar或者tab bar的高度自动调整。可以通过在storyboard的右侧进行设置,在Attributes Inspector中,不勾选“Adjust Scroll View Insets”。


翻译自:

http://stackoverflow.com/questions/19252852/extra-space-inset-in-scroll-view-at-run-time

参考:

http://stackoverflow.com/questions/20630059/why-uiscrollview-is-leaving-space-from-top-in-ios-6-and-ios-7

在 UIScrollView 上添加手势识别器时,有可能会出现手势冲突的情况。这通常是由于 UIScrollView 自身的手势识别器和添加的手势识别器之间的冲突引起的。 要解决这个问题,有几种可能的方法: 1. 禁用 UIScrollView 的手势识别器。这可以通过将 UIScrollView 的属性 `canCancelContentTouches` 和 `delaysContentTouches` 设置为 `NO` 来实现。但是,这样会使 UIScrollView 的滚动功能也被禁用,因此在某些情况下可能并不可取。 2. 使用手势识别器代理方法来控制手势冲突。在手势识别器代理方法 `gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:` 中,可以根据需要返回 `YES` 或 `NO`,以允许或禁止多个手势识别器同时识别手势。 3. 将手势识别器添加到 UIScrollView 的子视图中,而不是直接添加到 UIScrollView 上。这样,手势识别器就不会与 UIScrollView 的手势识别器冲突了。 下面是一个示例代码,演示了如何在 UIScrollView 上添加一个 UISwipeGestureRecognizer 手势识别器,并处理手势冲突的情况: ```objc // 创建一个 UISwipeGestureRecognizer 手势识别器 UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; // 设置手势方向 swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; // 将手势识别器添加到 UIScrollView 上 [scrollView addGestureRecognizer:swipeGestureRecognizer]; // 实现手势识别器代理方法,处理手势冲突 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if ([gestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]] && [otherGestureRecognizer.view isKindOfClass:[UIScrollView class]]) { return NO; // 禁止 UISwipeGestureRecognizer 和 UIScrollView 同时识别手势 } return YES; } // 处理 UISwipeGestureRecognizer 手势 - (void)handleSwipe:(UISwipeGestureRecognizer *)gestureRecognizer { // 处理手势事件 } ``` 希望这些提示可以帮助你解决 UIScrollView 上的手势冲突问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值