如何添加/使视图在滚动视图下可见?
我部分通过添加滚动视图,通过实例化 uiscrollview 子类(下面称为 ScrollViewManager)的类来覆盖 TouchEnded。问题是,虽然我的类现在具有滚动和触摸功能,但我无法再看到我的视图/笔尖文件,即使它可以很好地响应触摸和滚动。
我的想法是重新添加 MyClass nib 作为子视图?或者不知道...似乎它就在那里,但只是隐藏在这个滚动视图后面。
'Myclass : UIViewController ' 的摘录在 viewDidLoad 中有这些代码行,用于获取具有触摸响应的滚动操作。
太感谢了。就这么多了。
scrollView = [[ScrollViewManager alloc] initWithFrame:self.view.frame];
scrollView.contentSize = CGSizeMake(320, 600);
[scrollView setUserInteractionEnabled:TRUE];
[scrollView setScrollEnabled:TRUE];
self.view = scrollView;
//trying with this line to add my nib for this class on top of the scroll view
//which doesn't work: 'Accessing unknown 'view' class method'
[scrollView addSubview:Myclass.view];
[scrollView release];
I'm partially through adding a scrollview, by way of instantiating a class that subclasses uiscrollview (below called ScrollViewManager) to override touchesEnded. The problem is although my class now has scrolling and touch, I can't see my view/nib file anymore, even though it's responding to touches and scrolling fine.
My thoughts are to add back the MyClass nib as a subview? or don't know... Seems as though it's there but just hidden behind this scrollView.
The excerpt from 'Myclass : UIViewController ' has these lines of code in viewDidLoad to get the scroll action with touch response.
Thank you so much. So so much.
scrollView = [[ScrollViewManager alloc] initWithFrame:self.view.frame];
scrollView.contentSize = CGSizeMake(320, 600);
[scrollView setUserInteractionEnabled:TRUE];
[scrollView setScrollEnabled:TRUE];
self.view = scrollView;
//trying with this line to add my nib for this class on top of the scroll view
//which doesn't work: 'Accessing unknown 'view' class method'
[scrollView addSubview:Myclass.view];
[scrollView release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
self.view = scrollView 行使视图控制器指向的视图成为滚动视图。
即 self.view & scrollView 现在指向同一对象
当您尝试 [scrollView addSubview:Myclass.view]; 时, ;实际发生的情况是您将scrollView 添加到scrollView &访问滚动视图的视图属性。
只需删除 self.view = scrollView 行 &这样做
希望它会起作用。
self.view = scrollView line makes your view pointed by view controllers the scrollview.
ie self.view & scrollView now point to same object
after that when you are trying to [scrollView addSubview:Myclass.view]; what actually happening is you are adding scrollView to your scrollView & accessing view property of scrollview.
Just remove the self.view = scrollView line & do this
Hopefully it'll work.
由于某种原因,我无法向您的帖子添加评论。它不起作用。
Apple 在此处:但没有解释如何。他们的代码如下,用于添加滚动方面,就像我上面所做的那样。我现在正在尝试将我的视图添加为子视图:
但这会崩溃并且不去任何地方。不知道现在该怎么办。苹果的代码在这里,带有原始注释:
}
for some reason I can't add comments to your post. It didn't work.
Apple talks about adding the subview here: but doesn't explain how. Their code is below for adding the scroll aspect, as I did above. I'm now messing around with trying to add my view as a subview:
but that crashes and goes not where. Don't know what to do now. Apple's code here with original comments:
}