2014-10-20 67 views
0

我創造了滾動和UIButton的對像下面的代碼:很難滾動了滾動在Xcode 6

- (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]; 
    } 
} 

在iPhone 6,滾動視圖變得堅韌滾動,但是當我更換由按鈕標籤,它工作正常。

在iphone 5,5s中,沒關係; 它有什麼問題?

回答

0

第一個子類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)]; 

然後設置該屬性是

myScrollView.canCancelContentTouches = YES; 

這解決您的問題。

+0

是的,問題已經解決了,但問題是怎麼回事?你能解釋給我,還是給我發郵件([email protected])。我很感激,非常感謝! – FelixMLians 2014-10-20 11:09:22