我有一个功能,可以将主视图移到一边以显示 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/