ios - UIButton 不可点击

标签 ios objective-c uibutton

我有一个功能,可以将主视图移到一边以显示 UIButton。 View 内的按钮部分是可单击的,但按钮的右侧不是。 我已将 self.view.frame 更改为更大的数字,但我仍然面临同样的问题。我也试过使用 insertSubview:aboveSubview: 但这也没有帮助。

self.view.frame = CGRectMake(0, 0, 1600, 568);
_testView = [[UIView alloc]initWithFrame:CGRectMake(300, 20, 120, 100)];
_testView.backgroundColor = [UIColor greenColor];

UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
test.frame = CGRectMake(0, 0, 120, 100);
[test addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside];

[_testView addSubview:test];
[self.view addSubview:_testView];

- (void)showRightMenu
{
    CGRect frame = self.view.frame;
    frame.origin.x = -100;
self.view.frame = frame
}

编辑:我已经上传了我的问题的示例项目 https://dl.dropboxusercontent.com/u/137356839/TestMePlz.zip

最佳答案

在你把你的代码发给我之后我做了一些改变:

首先,我创建了一个容器 View (可以更轻松地跟踪所有 View ):

_contatinerView = [[UIView alloc] initWithFrame:self.view.frame];

所以你放在 self.view 中的所有 View 我都移到了 _containerView 中。然后我显然将 _containerView 添加到 self.view

而不是使用:

CGRect frame = self.view.frame;
frame.origin.x = -100;
self.view.frame = frame;

我做到了:

[_contatinerView setTransform:CGAffineTransformTranslate(_contatinerView.transform,-100, 0)];

您必须添加 QuartzCore 和 CoreGraphics 框架。

关于ios - UIButton 不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17400824/

相关文章:

支持位置跟踪的后台模式的 iOS 应用程序会在一段时间后自动关闭(并非在每个 session 中)

ios - 如果用户从 pickerView 中选择了一个字符串,我将如何将我的文本字段输入设置为 "0"或 "1"?

iphone - arc 的核心图内存消耗问题

iphone - UIButton:需要一个圆形点击区域

ipad - xcode 中的多个 PDF 页面和二维 ScrollView

ios - 如何防止 UITableView 在移动行时滚动

iphone - 关于dispatch_queue_t和dispatch_sync的调用

ios - 如何从 "Sign In with Apple"验证身份Token?

ios - 以编程方式更改n个按钮的按钮文本颜色,而无需更改其他按钮的文本颜色

ios - 以编程方式添加 UIButtons,然后按名称对它们进行排序,如 Swipes 应用程序