iphone - 触摸时触感更大

标签 iphone objective-c ios xcode cocoa-touch

我需要一种方法让用户在按下按钮时有更大的触感。这样用户就可以错过该按钮但仍然单击它。有没有办法做到这一点?我不想只更改用户单击的区域的按钮类..

谢谢!!! p.s我非常擅长逻辑思维...我只需要一些代码

最佳答案

1)你可以使用[yourButtonType setBackgroundImage:yourImage forState:UIControlStateNormal]; 你可以让你的形象像这样,

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

事实上按钮框架更大,但用户无法察觉

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
    }
}

关于iphone - 触摸时触感更大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11705447/

相关文章:

ios - 到目前为止字符串的正确格式?

iphone - 如何创建我自己的 Web API/Web 服务

iphone - 如何在 iPhone 中的部分 tableviewcell 中添加行

iphone - 当显示 Default.png 时,在启动期间在哪里更改状态栏的颜色

iPhone向应用程序添加计时器

objective-c - 从 UILabel 中显示的整数中减一

ios - AVAudioPlayer 播放新声音时卡住 UI

iphone - 我没有影子

android - 具有成员(member)设计的移动应用程序

android - Titanium 是否会将 iPhone 应用程序转换为 Android?