Skip to content

Commit

Permalink
Fixed unclickable button issue in production
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Zweier committed May 3, 2013
1 parent 77d5028 commit e3f7967
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions OBShapedButton/OBShapedButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ of this software and associated documentation files (the "Software"), to deal


@interface OBShapedButton ()
{
UIImage *buttonImage;
UIImage *buttonBackground;
}

@property (nonatomic, assign) CGPoint previousTouchPoint;
@property (nonatomic, assign) BOOL previousTouchHitTestResponse;
Expand Down Expand Up @@ -113,10 +117,6 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
} else {
self.previousTouchPoint = point;
}

// We can't test the image's alpha channel if the button has no image. Fall back to super.
UIImage *buttonImage = [self imageForState:UIControlStateNormal];
UIImage *buttonBackground = [self backgroundImageForState:UIControlStateNormal];

BOOL response = NO;

Expand Down Expand Up @@ -145,12 +145,16 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
// Reset the Hit Test Cache when a new image is assigned to the button
- (void)setImage:(UIImage *)image forState:(UIControlState)state
{
//If the image is going to change this will be called, we can avoid grabbing a new image every touch.
buttonImage = image;
[super setImage:image forState:state];
[self resetHitTestCache];
}

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
{
//If the background image is going to change this will be called, we can avoid grabbing a new image every touch.
buttonBackground = image;
[super setBackgroundImage:image forState:state];
[self resetHitTestCache];
}
Expand Down

0 comments on commit e3f7967

Please sign in to comment.