我有一个应用程序,其按钮覆盖整个屏幕,按钮顶部有较小的按钮。当我按下按钮时,我写了一个显示手指位置的文本,但是当我将手指放在某些区域时,我看不到任何东西,按钮停止工作(屏幕的右下方区域)我确定在那里那里什么都没有。这是代码:
.h 文件:
{
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 文件
{
viewDidLoad
{
BigButton = [UIButton buttonWithType: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;
}
我确定按钮 BigButton 上方没有任何按钮或任何类型的视图,尽管在不可见区域上方有一个按钮,虽然很远