简体   繁体   English

触摸时更大的触摸

[英]Bigger Touch when touching

I need a way for the user to have a bigger touch when in comes to pressing a button. 我需要一种让用户在按下按钮时拥有更大触感的方法。 This way the user can miss the button but still click it. 这样,用户可以错过按钮,但仍可以单击它。 Is there a way to do this? 有没有办法做到这一点? I don't want to change the button class just the area in which the user clicks.. 我不想仅在用户单击的区域更改按钮类。

Thanks!!! 谢谢!!! ps I'm pretty good at logical thinking... I just need some code ps我很擅长逻辑思维...我只需要一些代码

1)you can use [yourButtonType setBackgroundImage:yourImage forState:UIControlStateNormal]; 1)您可以使用[yourButtonType setBackgroundImage:yourImage forState:UIControlStateNormal]; you could make you image like this, 你可以让你这样的形象,

-------------------------------------------
| transparent, transparent, transparent   |
| transparent,yourOpaqueImage, transparent|
| transparent, transparent, transparent   |
|------------------------------------------

In fact the button frame is larger , but the user can not aware 实际上按钮框较大,但用户无法意识到

2)you can use touchesEnded,like this 2)您可以使用touchesEnded,像这样

- (void)touchesEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint location = [touch locationInView:self];
    CGRect btnRect = CGRectMake(btn.frame.origon.x-10,btn.frame.origon.y-10 , btn.frame.size.width+20, btn.frame.size.height+20);
    if (CGRectContainsPoint(btnRect, location)) {
         //sender your button
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM