如何添加/使视图在滚动视图下可见?

发布于 2024-10-22 05:56:28 字数 765 浏览 1 评论 0原文

我部分通过添加滚动视图,通过实例化 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失眠症患者 2024-10-29 05:56:28

self.view = scrollView 行使视图控制器指向的视图成为滚动视图。
即 self.view & scrollView 现在指向同一对象

当您尝试 [scrollView addSubview:Myclass.view]; 时, ;实际发生的情况是您将scrollView 添加到scrollView &访问滚动视图的视图属性。

只需删除 self.view = scrollView 行 &这样做

[self.view addSubView:scrollView];
[scrollView release];

希望它会起作用。

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

[self.view addSubView:scrollView];
[scrollView release];

Hopefully it'll work.

独留℉清风醉 2024-10-29 05:56:28

由于某种原因,我无法向您的帖子添加评论。它不起作用。
Apple 在此处:但没有解释如何。他们的代码如下,用于添加滚动方面,就像我上面所做的那样。我现在正在尝试将我的视图添加为子视图:

 UIView *newView = [[NSBundle mainBundle] loadNibNamed:@"MyClassView" owner:self options: nil];
[scrollView addSubview:newView];

但这会崩溃并且不去任何地方。不知道现在该怎么办。苹果的代码在这里,带有原始注释:

  (void)loadView {
    CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
    scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
    self.view=scrollView;
    scrollView.contentSize=CGSizeMake(320,758);
    scrollView.contentInset=UIEdgeInsetsMake(64.0,0.0,44.0,0.0);


// do any further configuration to the scroll view
// add a view, or views, as a subview of the scroll view.

// release scrollView as self.view retains it
self.view=scrollView;
[scrollView release];

}

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:

 UIView *newView = [[NSBundle mainBundle] loadNibNamed:@"MyClassView" owner:self options: nil];
[scrollView addSubview:newView];

but that crashes and goes not where. Don't know what to do now. Apple's code here with original comments:

  (void)loadView {
    CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
    scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
    self.view=scrollView;
    scrollView.contentSize=CGSizeMake(320,758);
    scrollView.contentInset=UIEdgeInsetsMake(64.0,0.0,44.0,0.0);


// do any further configuration to the scroll view
// add a view, or views, as a subview of the scroll view.

// release scrollView as self.view retains it
self.view=scrollView;
[scrollView release];

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文