简体   繁体   中英

How to make current view a scrollview? iOS / Objective C

I have a view (that is actually part of a UINavigationControllers view) that i want to make a scrollview.

how do i do that?

could i do something like this:

UIScrollView * content = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.view = content

(obviously that doesn't work, but is there a way to do it like that)?

Yes, it is, you have to implement delegates, and set the contentSize. The best tutorial on scrollViews ever I found is:

http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content

You are on a good way!

You can create the scroll view programmatically like you do and then add the existing view as a subview of this new scroll view, examine addSubview: (which works on all UIView s and subclasses like UIScrollView as well). I won't say this is the solution or even a clean one for that matter, but if you read about addSubview: you can at least figure out how to have a view live inside a scroll view...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM