I have an app with a button covering the whole screen and with smaller buttons on top of this button. When I press the button I write a text that shows the position of the finger, but when I put my finger over certain areas, where I can not see anything, the button stops working (lower right area of the screen) I am certain there is nothing there. Here is the code:
.h file:
{
UIButton *BigButton;
CGPoint FingerPos;
bool isFingerDown;
UILabel *FingerPosLabel;
}
-(void)Update;
-(IBAction)FingerMoved:(id)sender withEvent:(UIEvent*)event;
-(IBAction)FingerPressed:(id)sender withEvent:(UIEvent*)event;
-(IBAction)FingerReleased:(id)sender withEvent:(UIEvent*)event;
.m file
{
viewDidLoad
{
BigButton = [UIButton buttonWithTy开发者_C百科pe:UIButtonTypeCustom];
[BigButton setFrame:CGRectMake(0, 0, 300, 480)];
[self.view addSubview:BigButton];
FingerPos = CGPointMake(0, 0);
isFingerDown = false;
FingerPosLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 300, 50)];
[self.view addSubview:FingerPosLabel];
[FingerPosLabel setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]];
[FingerPosLabel setTextColor:[UIColor redColor]];
[BigButton addTarget:self action:@selector(FingerPressed:withEvent:) forControlEvents:UIControlEventTouchDown];
[BigButton addTarget:self action:@selector(FingerReleased:withEvent:) forControlEvents:UIControlEventTouchUpInside];
[BigButton addTarget:self action:@selector(FingerMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
}
-(IBAction)FingerPressed:(id)sender withEvent:(UIEvent *)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint endingPosition = [touch locationInView:self.view];
FingerPos = endingPosition;
isFingerDown = true;
}
-(IBAction)FingerMoved:(id)sender withEvent:(UIEvent *)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint endingPosition = [touch locationInView:self.view];
FingerPos = endingPosition;
}
-(IBAction)FingerReleased:(id)sender withEvent:(UIEvent *)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint endingPosition = [touch locationInView:self.view];
FingerPos = endingPosition;
isFingerDown = false;
}
I an certain there are no buttons or views of any kind above the button BigButton, though there is a button above the invisible area, though far up
Question solved. The screen was on landscape and the button was not wide enough. I inverted the width and height (should be 480, 300)
精彩评论