Wednesday, 11 September 2013

Anyone else having trouble with the UIView touches methods in iOS7?

Anyone else having trouble with the UIView touches methods in iOS7?

I had to create my own custom ButtonView class to sort of reimplement the
look of the bordered UIButton in iOS6 (I plan on updating the art work
eventually though). The implementation is as follows:
@implementation ButtonView
#pragma mark -
#pragma mark Instance Variables
@synthesize titleLabel = _titleLabel;
@synthesize delegate = _delegate;
#pragma mark -
#pragma mark Initializers
- (id)initWithFrame:(CGRect)frame title:(NSString*)title
titleSize:(CGFloat)titleSize
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor whiteColor];
self.layer.borderWidth = 1;
self.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.layer.cornerRadius = 10;
self.layer.masksToBounds = YES;
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,
self.bounds.size.width, self.bounds.size.height)];
self.titleLabel.text = title;
self.titleLabel.font = [UIFont fontWithName:FONTNAME size:titleSize];
self.titleLabel.textColor = [UIColor blackColor];
self.titleLabel.backgroundColor = [UIColor clearColor];
self.titleLabel.textAlignment = UITextAlignmentCenter;
[self addSubview:self.titleLabel];
}
return self;
}
#pragma mark -
#pragma mark UIView Methods
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
self.backgroundColor = [UIColor blueColor];
self.titleLabel.textColor = [UIColor whiteColor];
if ([self.delegate
respondsToSelector:@selector(buttonViewDidTouchDown:)])
{
[self.delegate buttonViewDidTouchDown:self];
}
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchedPoint = [[touches anyObject] locationInView:self];
if (![self touchedPointIsInsideBounds:touchedPoint])
{
self.backgroundColor = [UIColor whiteColor];
self.titleLabel.textColor = [UIColor blackColor];
}
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchedPoint = [[touches anyObject] locationInView:self];
if ([self touchedPointIsInsideBounds:touchedPoint])
{
self.backgroundColor = [UIColor whiteColor];
self.titleLabel.textColor = [UIColor blackColor];
if ([self.delegate
respondsToSelector:@selector(buttonViewDidTouchUpInside:)])
{
[self.delegate buttonViewDidTouchUpInside:self];
}
}
else
{
if ([self.delegate
respondsToSelector:@selector(buttonViewDidTouchUpOutside:)])
{
[self.delegate buttonViewDidTouchUpOutside:self];
}
}
}
#pragma mark -
#pragma mark UIView Methods
- (BOOL) touchedPointIsInsideBounds:(CGPoint)touchedPoint
{
if ((touchedPoint.x >= 0 && touchedPoint.x <= self.bounds.size.width)
&& (touchedPoint.y >= 0 && touchedPoint.y <= self.bounds.size.height))
{
return YES;
}
else
{
return NO;
}
}
@end
With this method I'm having issues with the UIView touch methods. For
instance, after I tap the button, there is a hiccup before the button does
what it's supposed to do. When I run this code in iOS6, it works
perfectly. Has anyone else had issues with these methods or
UIGestureRecognizer? I seem to be having trouble with these touch methods
in my app where in iOS6 they worked fine.

No comments:

Post a Comment