我试图弄清楚当 touchesmoved 离开当前选定按钮的框架时如何设置按钮不被突出显示。请参阅下面的代码。下面的代码应该允许单独按下和滑动三个按钮中的任何一个。我遇到的问题是,当按钮滑动时,例如使用 touchesmoved,按钮调用动作,但当滑动离开按钮框架时,从不将按钮设置回不突出显示。
提前致谢,
阿扎
- (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event {
for(UITouch *t in touches) {
CGPoint location = [t locationInView:t.view];
if((CGRectContainsPoint(Button1.frame, location)) && (!Button1.isHighlighted))
{
if (!Button1.isHighlighted){
[Button1 setHighlighted:YES];
[self doAction1];
}else{
[Button1 setHighlight:NO];
}
}
if((CGRectContainsPoint(Button2.frame, location)) && (!Button2.isHighlighted))
{
if (!Button2.isHighlighted){
[Button2 setHighlighted:YES];
[self doAction2];
}else{
[Button2 setHighlight:NO];
}
}
if((CGRectContainsPoint(Button3.frame, location)) && (!Button3.isHighlighted))
{
if (!Button3.isHighlighted){
[Button3 setHighlighted:YES];
[self doAction3];
}else{
[Button3 setHighlight:NO];
}
}
}
- (void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event {
for(UITouch *t in touches) {
CGPoint location = [t locationInView:t.view];
if(CGRectContainsPoint(Button1.frame, location))
{
if (!Button1.isHighlighted){
[Button1 setHighlighted:YES];
[self doAction1];
}
}
if(CGRectContainsPoint(Button2.frame, location))
{
if (!Button2.isHighlighted){
[Button2 setHighlighted:YES];
[self doAction2];
}
}
if(CGRectContainsPoint(Button3.frame, location))
{
if (!Button3.isHighlighted){
[Button3 setHighlighted:YES];
[self doAction3];
}
}
}
- (void)touchesEnded: (NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *t in touches){
CGPoint location = [t locationInView:self.view];
if(CGRectContainsPoint(Button1.frame, location)) {
[Button1 setHighlighted:NO];
} else if(CGRectContainsPoint(Button2.frame, location)) {
[Button2 setHighlighted:NO];
} else if(CGRectContainsPoint(Button3.frame, location)) {
[Button3 setHighlighted:NO];
}
}
}