2013-11-21 321 views
0

因此,我的照片應用程序中的過濾器按鈕出現問題。我不確定爲什麼,但他們突然停止工作。當選擇器被輕敲時不會被調用,但我不知道爲什麼。他們幾天前工作得很好,但由於某種原因,他們現在不是。我已經檢查過UIView子視圖數組,驗證它是正確的。我需要一種方法來查看是否由於某種原因,觸摸沒有進入按鈕。我不知道如何做到這一點。UIButton突然停止工作

我希望我有更多的信息給予,但這是我所擁有的。我希望有人提出一些建議,因爲我的智慧已經結束了。

在此先感謝!

按鈕創建方法:

-(void)createFilterButtonsForThumbnail:(UIImage *)thumbnail 
{ 
    UIView *filtersContainer = self.filterContainer; 
    CGRect buttonFrame = CGRectMake(kFilterFrameThickness, kFilterFrameThickness, 
            thumbnail.size.width, thumbnail.size.height); 

    CGFloat frameWidth = thumbnail.size.width+(2*kFilterFrameThickness); 
    CGFloat frameHeight = kFilterPickerHeight; 

    UIEdgeInsets backgroundInsets = UIEdgeInsetsMake(0, kFilterFrameThickness, 0, kFilterFrameThickness); 
    UIImage *buttonBackgroundImage = [[UIImage imageNamed:@"FilmReel"] resizableImageWithCapInsets:backgroundInsets]; 

    for (int i = 0;i<(self.filterPaths.count+kFilterNonLookups+1);i++){ 


     UIImageView *buttonBackground = [[UIImageView alloc] initWithFrame:CGRectMake(kFilterSidePadding+(i*(frameWidth+kFilterSidePadding)), 
                      0, 
                      frameWidth, 
                      frameHeight)]; 
     [buttonBackground setImage:buttonBackgroundImage]; 

     UIButton *thumbnailButton = [[UIButton alloc] initWithFrame:buttonFrame]; 
     UIImage *filteredThumbnail = [self applyFilterAtIndex:i ToImage:thumbnail]; 

     [thumbnailButton setImage:filteredThumbnail forState:UIControlStateNormal]; 
     [thumbnailButton addTarget:self action:@selector(filterSelected:) forControlEvents:UIControlEventTouchUpInside]; 
     [thumbnailButton setTag:i]; 

     [buttonBackground addSubview:thumbnailButton]; 
     [filtersContainer addSubview:buttonBackground]; 
     if ((i > (kFilterProMinimumIndex)) && ([self isProVersion]) == NO){ 
      UIImageView *proTag = [[UIImageView alloc] initWithImage:nil]; 
      CGRect proFrame = CGRectMake(buttonFrame.origin.x, 
             buttonFrame.origin.y + buttonFrame.size.height - kFilterProIconHeight-kFilterFrameThickness, 
             kFilterProIconWidth, 
             kFilterProIconHeight); 
      [proTag setBackgroundColor:[UIColor orangeColor]]; 
      [proTag setFrame:proFrame]; 
      [thumbnailButton addSubview:proTag]; 
      [self.filterProTags addObject:proTag]; 
     } 
    } 
} 

選擇方法:

-(void)filterSelected:(UIButton *)button 
{ 
    NSLog(@"Pressed button for index %i",button.tag); 
    int buttonTag = button.tag; 
    if ((buttonTag < kFilterProMinimumIndex+1) || ([self isProVersion] == YES)){ 
     [self.imageView setImage:[self applyFilterAtIndex:buttonTag ToImage:self.workingImage]]; 
    } 
    else { 
     [self processProPurchaseAfterAlert]; 
    } 
} 

回答

4

我看到一對夫婦問題,這一點,但我不知道哪些是導致其破裂。首先,你應該使用的UIButton實例buttonWithType:您的按鈕:

UIButton *thumbnailButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[thumbnailButton setFrame:buttonFrame] 

這樣做的原因是UIButton的是一類集羣,你應該讓操作系統給你正確的按鈕。

其次,您將按鈕添加爲UIImageView的子視圖,默認情況下,該按鈕的userInteractionEnabled設置爲NO

該屬性繼承自UIView父類。此類 將此屬性的默認值更改爲NO。

你應該有一個大按鈕,按鈕的背景是你想要的圖像。

+0

我實際上已經嘗試了頂部,它沒有修復它,所以我抹去了它。爲了約定,我把它放回去了。但是,在背景和按鈕上的userInteractionEnabled都設置爲YES,這明確地解決了這個問題。非常感謝你,我無法弄清楚這一點! – Rob