2013-11-21 312 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