Graphics Programs Reference
In-Depth Information
Notice that you can stop in between the two HypnosisView s. Sometimes you want this,
but other times, you do not. To force the scroll view to snap its viewing port to one of the
views, turn on paging for the scroll view in HypnosisterAppDelegate.m .
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:screenRect];
[scrollView setPagingEnabled:YES];
[[self window] addSubview:scrollView];
Build and run the application. Pan to the middle of two HypnosisView s and see how it
automatically scrolls to one of the views. Paging works by taking the size of the scroll
view's bounds and dividing up the contentSize it displays into sections of the same
size. After the user pans, the view port will scroll to show only one of these sections.
Zooming
A UIScrollView can also zoom in and out on its content. To zoom, a scroll view needs
to know the minimum and maximum zoom levels, and it needs to know the view to zoom
in on.
A UIScrollView can technically only zoom in on one view. So remove the code that
creates another HypnosisView in HypnosisterAppDelegate.m and change the
contentSize of the UIScrollView back to the size of the screen.
CGRect bigRect = screenRect;
bigRect.size.width *= 2.0;
HypnosisView *view = [[HypnosisView alloc] initWithFrame:screenRect];
[scrollView addSubview:view];
screenRect.origin.x = screenRect.size.width;
HypnosisView *anotherView = [[HypnosisView alloc] initWithFrame:screenRect];
[scrollView addSubview:anotherView];
[scrollView setContentSize:bigRect.size];
Then, in HypnosisterAppDelegate.m , disable paging and set the zoom properties
and delegate of the UIScrollView .
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:screenRect];
[scrollView setPagingEnabled:YES];
[scrollView setMinimumZoomScale:1.0];
[scrollView setMaximumZoomScale:5.0];
// You will get a warning here, ignore it for now
[scrollView setDelegate:self];
[[self window] addSubview:scrollView];
Build and run the application. You should see one HypnosisView , which you cannot
pan or zoom.
 
Search WWH ::




Custom Search