ios - UIButton 在 iOS7 中的 UIPageViewController 中的 ViewController 中没有突出显示

标签 ios ios7 uipageviewcontroller

我在 View Controller 中有一个 UIButton,它嵌入在 UIPageViewController 中。页面 View Controller 处于滚动模式(所以没有手势)。当我触摸按钮时,将调用操作方法,但按钮没有发生可见状态更改(突出显示状态)。这意味着按钮看起来没有被触及。仅在 iOS7 中观察到。有什么解决办法吗?

案例 1:在 Normal ViewController 中,带有和不带有 Tap 的 Button 的行为

Before tapping After tapping

案例 2:在 PageViewController 的 viewController 之一中,使用和不使用 Tap 时 Button 的行为

Before tapping enter image description here

最佳答案

当您在 UIScrollView 中放置一个按钮时,通常会发生这种情况。 UIScrollView 有一个名为“dalaysContentTouches”的属性,默认为 YES。如果是,那么按钮上的触摸将被延迟(以便有时间检查它是否是滚动手势),因此您不会看到高亮显示。不过,如果您点击它,它将注册为按下按钮,而不会突出显示。

我不确定您的设置到底是什么,但这似乎是一个类似的问题。检查您的 UI 中涉及的所有手势识别器,并检查“delaysTouchesBegan”和“delaysTouchesEnded”的值。

**实验后编辑**

我刚刚在 iOS 7.0 上试用了这个,它似乎可以解决问题。

-(void)viewDidAppear:(BOOL)animated {
    NSArray *subviews = self.pageViewController.view.subviews;
    NSArray *viewHierarchy = [@[self.pageViewController.view] arrayByAddingObjectsFromArray:subviews];
    int i = 0;
    for (UIView *viewToCheck in viewHierarchy) {
        for (UIGestureRecognizer *gestureRecognizer in viewToCheck.gestureRecognizers) {
            NSLog(@"%d gestureRecognizer: %@", i++, gestureRecognizer);
            gestureRecognizer.delaysTouchesBegan = NO;
        }
    }
}

我得到了这个输出

0 gestureRecognizer: <UIScrollViewDelayedTouchesBeganGestureRecognizer: 0x8e9b510; state = Possible; delaysTouchesBegan = YES; view = <_UIQueuingScrollView 0x9b7f800>; target= <(action=delayed:, target=<_UIQueuingScrollView 0x9b7f800>)>>
1 gestureRecognizer: <UIScrollViewPanGestureRecognizer: 0x8e9ba10; state = Possible; delaysTouchesEnded = NO; view = <_UIQueuingScrollView 0x9b7f800>; target= <(action=handlePan:, target=<_UIQueuingScrollView 0x9b7f800>)>; must-fail = {
        <UIScrollViewPagingSwipeGestureRecognizer: 0x8e9bec0; state = Possible; view = <_UIQueuingScrollView 0x9b7f800>; target= <(action=_handleSwipe:, target=<_UIQueuingScrollView 0x9b7f800>)>>
    }>
2 gestureRecognizer: <UIScrollViewPagingSwipeGestureRecognizer: 0x8e9bec0; state = Possible; view = <_UIQueuingScrollView 0x9b7f800>; target= <(action=_handleSwipe:, target=<_UIQueuingScrollView 0x9b7f800>)>; must-fail-for = {
        <UIScrollViewPanGestureRecognizer: 0x8e9ba10; state = Possible; delaysTouchesEnded = NO; view = <_UIQueuingScrollView 0x9b7f800>; target= <(action=handlePan:, target=<_UIQueuingScrollView 0x9b7f800>)>>
    }>

它揭示了一个 UIScrollViewDelayedTouchesBeganGestureRecognizer,它似乎是 PageController 的自定义识别器,旨在对您的按钮执行此操作...

但是!将其 delaysTouchesBegan 属性设置为 NO,按钮高亮显示会在按下时立即出现。希望这对你也有用。

关于ios - UIButton 在 iOS7 中的 UIPageViewController 中的 ViewController 中没有突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22093080/

相关文章:

ios - 模态视图 Controller 在 iOS 7 上工作,在 iOS 6 上留下一个空白

swift - PageViewController 嵌入在其他 PageViewController 中

ios - 更改 UIPageControl 的位置

ios - 无法重命名源代码 - 出现错误 'Thread1: signal SIGABRT'

ios - 由于 SSO 导致 AppCenter 拒绝

ios - ios 6 中带有文本字段和三个按钮问题的 UIAlertView

opencv - 如何为iOS7构建OpenCV 2.4.8?

ios - 从 plist 中检索多行

ios - 如何在 swift 中使用 dbAccess 的特定字段更新多条记录

android - 如何在 iOS 中创建滑动页面?就像在 Android 中使用 FragmentStatePagerAdapter