2012-11-20 17 views
0

我添加到滾動視圖中的按鈕有一個奇怪的行爲。將按鈕添加到滾動視圖時未調用該操作

for (UIView *subview in self.scrollView.subviews) { 
     [subview removeFromSuperview]; 
    } 
    //Create and place info Button(s) 
    for (int i = 0; i < BigPictures.count; i++) { 
     UIButton *infoButton = [[UIButton alloc] initWithFrame:CGRectMake(scrollView.frame.size.width*(i+1) - 29 - 5 - 10, scrollView.frame.size.height - 29 - 5, 29, 29)]; 
     [infoButton addTarget:self action:@selector(flip) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside]; 
     //[infoButton setEnabled:YES]; 
     //[infoButton setUserInteractionEnabled:YES]; 

     [self.scrollView addSubview:[FrontViews objectAtIndex:i]]; 
     [infoButton setBackgroundImage:[UIImage imageNamed:@"btn_image-info.png"] forState:UIControlStateNormal]; 
     [scrollView addSubview:infoButton]; 

BigPictures包含我想在滾動視圖中顯示的所有圖像。 現在到了奇怪的事情。如果BigPictures包含1個圖像,則動作(翻轉)被調用。只要[BigPictures count]> 1,那麼第一個圖像上的按鈕不會執行操作,但所有其他按鈕(第2-n頁)都是。那麼這怎麼可能?

即使我更改for (int i = 0; i < BigPictures.count; i++)for (int i = 0; i < 1; i++)然後按鈕正在工作。

那麼我錯過了什麼?已經嘗試過的東西,如

scrollView.delaysContentTouches = NO; 
scrollView.canCancelContentTouches = NO; 

但後者禁用scrollview的滾動。

編輯: 我試着將其他按鈕放在不同的位置,並沒有一個在第一頁上工作(如果頁面> 1)。還試圖放置一個GestureRecognizer。這工作,但if ([touch.view isKindOfClass:[UIButton class]])沒有檢測到下面的按鈕。所有在滾動視圖中的其他頁面上正常工作。真奇怪。

回答

0

做了一個完整的重建,現在它的工作。真的很奇怪,因爲我使用了完全相同的代碼。

相關問題