[英]simple uiview change not working
I am trying to just do a simple view change for proof of concept. 我试图做一个简单的视图更改以证明概念。
here is the code 这是代码
- (void)swipedScreen
{
if (self.secondView.superview == nil) {
[myView removeFromSuperview];
[self.view insertSubview:secondView atIndex:0];
}
}
when I swipe the screen what happens is the view area just goes black... and becomes unresponsive. 当我滑动屏幕时,发生的情况是视图区域变黑...并且变得无响应。
I started with a navigatoin app, replaced the tableview with just a standard uiviewcontroller class.. that worked fine..Then i added a secondView (xib only) and changed its class to match the viewcontroller of the first view. 我从一个navigatoin应用程序开始,用一个标准的uiviewcontroller类替换了tableview,效果很好。.然后我添加了secondView(仅Xib)并更改了其类以匹配第一个视图的viewcontroller。
The reason I am finding this difficult is because i am trying to animate the views inside the navigation controller and not push a whole view onto the stack which I am used to doing. 我发现这很困难的原因是因为我试图使导航控制器内部的视图动画化,而不是将整个视图压入我惯常使用的堆栈中。
I'll bet that blank unresponsive view is, in reality, your secondView
object. 我敢打赌,空白的无响应视图实际上是您的secondView
对象。 I always test by setting [secondView setBackgroundColor:[UIColor greenColor]]
and checking if the massive green rectangle actually shows up. 我总是通过设置[secondView setBackgroundColor:[UIColor greenColor]]
并检查是否真正显示了绿色矩形来进行测试。
EDIT: having looked at your code, there are multiple problems that arose: 编辑:看过您的代码后,出现了多个问题:
+alloc
or -init
anything. 您从不实际+alloc
或-init
任何东西。 I've taken the liberty of revising it (sans nibs). 我采取了修改它的自由(无笔尖)。 Take a look . 看一看 。
Did you init the secondView? 您是否初始化了secondView? if init,you can try to set frame for the secondView 如果是init,则可以尝试为secondView设置框架
Your inserting the view at the bottom of the stack, 您将视图插入堆栈的底部,
[self.view insertSubview:secondView atIndex:0];
Try using addSubview instead. 尝试改用addSubview。 Also you need to set the views frame somewhere. 另外,您需要在某处设置视图框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.