开发者

how to add/make the view visible under a scrollView?

开发者 https://www.devze.com 2023-02-17 03:18 出处:网络
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

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 s开发者_如何转开发o 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];


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.


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];

}

0

精彩评论

暂无评论...
验证码 换一张
取 消