使用按钮切换视图
我有一个带有四个按钮的主视图,每次单击按钮时都会添加一个子视图。但是当我单击该按钮并出现子视图时,我无法按任何其他按钮。有人有什么建议吗?单击按钮时的代码如下:
newView = [[UIView alloc] initWithFrame:CGRectMake(25,25,50,20)];
[newView addSubview: testArena.view];
[newView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)];
[UIView beginAnimations:@"animateArenaView" context:nil];
[UIView setAnimationDuration:0.4];
[newView setFrame:CGRectMake( 0.0f, 20.0f, 320.0f, 460.0f)];
[UIView commitAnimations];
[newView setUserInteractionEnabled:YES];
[self.view addSubview: newView];
其中 newView 是 UIView,testArena.view 是我要从中显示视图的类。
I have a main view with four buttons, each time a button is clicked a subview is added. But when I click the button, and the subview comes up, I can´t pressed any of the other buttons. Does anyone have any suggestions? Here´s the code when a buttons is clicked:
newView = [[UIView alloc] initWithFrame:CGRectMake(25,25,50,20)];
[newView addSubview: testArena.view];
[newView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)];
[UIView beginAnimations:@"animateArenaView" context:nil];
[UIView setAnimationDuration:0.4];
[newView setFrame:CGRectMake( 0.0f, 20.0f, 320.0f, 460.0f)];
[UIView commitAnimations];
[newView setUserInteractionEnabled:YES];
[self.view addSubview: newView];
Where newView is a UIView, and testArena.view is the class I´m getting the view I want displayed from.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来 newView 可能隐藏/阻止按钮被按下?尝试将其发送到后面,这样它就不会覆盖按钮:
Sounds like newView might be hiding/stopping the buttons from being pressed? Try sending it to the back, so it can't cover the buttons:
当您单击其中的一个按钮时,您可以禁用所有其他按钮..
if(button1){
按钮2用户交互启用=否;
按钮3用户交互启用=否;
按钮4用户交互启用=否;
}
如果(按钮2){
按钮1用户交互启用=否;
按钮3用户交互启用=否;
按钮4用户交互启用=否;
}
...
..
while you click on one button inside that you can disable all other buttons..
if(button1){
button2 userinteraction enable = no;
button3 userinteraction enable = no;
button4 userinteraction enable = no;
}
if(button2){
button1 userinteraction enable = no;
button3 userinteraction enable = no;
button4 userinteraction enable = no;
}
...
..