难以滚动Xcode 6中的滚动视图



我在上面创建了scrollView和UIButton,就像下面的代码一样:

- (void)viewDidLoad {
    [super viewDidLoad];
    myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, 375, 60)];
    myScrollView.contentSize = CGSizeMake(375*4, 60);
    myScrollView.pagingEnabled = YES;
    myScrollView.backgroundColor = [UIColor orangeColor];
    myScrollView.userInteractionEnabled = YES;
    [self.view addSubview:myScrollView];
    for (int i = 0; i < 4 ; i ++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(75 + 375*i, 0, 300, 60)];
        [btn setTitle:[NSString stringWithFormat:@"Button %d",i+1] forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor brownColor];
        [btn addTarget:self action:@selector(ButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [myScrollView addSubview:btn];
    }
}

在iphone6上,滚动视图变得很难滚动,但当我用标签替换按钮时,它正常工作。

在iphone5,5s中,一切正常;它怎么了?

第一个子类UIScrollview并将此函数添加到.m文件中。

     - (BOOL)touchesShouldCancelInContentView:(UIView *)view{
if ( [view isKindOfClass:[UIButton class]] ) {
    return YES;
}
return [super touchesShouldCancelInContentView:view];}

使用子类作为滚动视图

myScrollView = [[myScroll alloc] initWithFrame:CGRectMake(0, 200, 375, 60)];

然后设置此属性YES

myScrollView.canCancelContentTouches = YES;

这解决了你的问题。

最新更新