代码之家  ›  专栏  ›  技术社区  ›  Alex L

UIPageControl不响应触摸,不改变点

  •  6
  • Alex L  · 技术社区  · 14 年前

    我有一个UIPageControl。当我点击一个点来改变页面时,什么也没有发生。第二个点不会突出显示。

    不过,当我滚动UIScrollView时,它工作得很好。在这种情况下,第二个点会突出显示。

    pageControl = [[UIPageControl alloc] init] ;
    pageControl.center = CGPointMake(160.0f, 430.0f);
    pageControl.numberOfPages=nPages;
    pageControl.currentPage=0;
    pageControl.hidesForSinglePage = YES;
    pageControl.userInteractionEnabled =YES;
    
    [pageControl addTarget:self action:@selector(pageTurn:) forControlEvents:UIControlEventValueChanged];
    
    [self.view addSubview:pageControl];
    

    当我更改pageControl值时应该调用它,但它不会被调用,因为它对touch没有响应。

    - (void) pageTurn: (UIPageControl *) aPageControl
    {
        int whichPage = aPageControl.currentPage;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3f];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        sv.contentOffset = CGPointMake(320.0f * whichPage, 0.0f);
        [UIView commitAnimations];
    }
    
    4 回复  |  直到 14 年前
        1
  •  17
  •   user467105 user467105    14 年前

    设置pagecontrol的框架(宽度和高度)而不仅仅是中心,否则它的尺寸为零并且不响应触摸。

    pageControl = [[UIPageControl alloc] 
                     initWithFrame:CGRectMake(100, 430, 200, 50)];
    pageControl.center = CGPointMake(160.0f, 430.0f);
    
        2
  •  4
  •   Matthew Leffler    14 年前

    我的应用程序最近也出现了同样的症状。我的解决办法是 UIPageControl 在视图层次结构中向上(如果愿意,请使用z-index),使其位于 UIScrollView 在根视图中。如果它不高于 界面视图 它不会被触摸,即使它看起来是可见的。

    我不确定这是否是你的问题,但我想我会插嘴的。

        3
  •  2
  •   Peter Kreinz    11 年前

    有时将pageControl置于所有重叠子视图的前面会有帮助。

    这就是我的诀窍:

      [self.view bringSubviewToFront: pageControl];
    
        4
  •  2
  •   flame3    11 年前

    有时,当pagecontrol宽度太小时,也会发生这种情况。尝试将pagecontrol组件的宽度设置为相当大,例如320。那么它应该会工作得更好。