1

我有一个功能,可以将主视图移到一侧以显示UIButton. 视图内的按钮部分是可点击的,但按钮的右侧不是。我已将 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

4

3 回答 3

2

在您将代码发送给我后,我更改了一些内容:

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

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

所以你提出的所有观点self.view我都移到了_containerView。然后我显然添加了_containerViewto self.view

而不是使用:

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

我做了:

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

您必须添加 QuartzCore 和 CoreGraphics 框架。

于 2013-07-01T11:02:23.223 回答
0

尝试这个:

[test addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventTouchUpInside];

然后改变你的方法:

-(void)doSomething:(id)sender
{
    NSLog(@"Bug Fixes:!!!!!!!");
}

我在您的项目中做到了,并且按钮有效。

于 2013-07-01T13:58:43.430 回答
0

Please correct position of your View :

self.view.frame = CGRectMake(0, 0, 320, 568);
_testView = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 320, 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];

Thanks.

于 2013-07-01T10:17:42.417 回答