Graphics Programs Reference
In-Depth Information
HypnosisView *view =
[[HypnosisView alloc] initWithFrame:[[self window] bounds]];
// Create the HypnosisView with a frame that is twice the size of the screen
CGRect bigRect = screenRect;
bigRect.size.width *= 2.0;
bigRect.size.height *= 2.0;
HypnosisView *view = [[HypnosisView alloc] initWithFrame:bigRect];
[[self window] addSubview:view];
// Add the HypnosisView as a subview of the scrollView instead of the window
[scrollView addSubview:view];
// Tell the scrollView how big its virtual world is
[scrollView setContentSize:bigRect.size];
BOOL success = [view becomeFirstResponder];
Build and run your application. You can pan your view up and down, left and right.
Panning and paging
In the last example, a scroll view was used to move around a much larger view. A scroll
view can pan between a number of different view instances. For example, if there are two
screen-sized views, a user could pan between them. In HypnosisterAppDeleg-
ate.m , shrink the HypnosisView back to the size of the screen and add another
screen-sized HypnosisView as a subview of the UIScrollView . Also, make the
contentSize twice as wide as the screen, but the same height.
CGRect bigRect = screenRect;
bigRect.size.width *= 2.0;
bigRect.size.height *= 2.0;
HypnosisView *view = [[HypnosisView alloc] initWithFrame:bigRect];
HypnosisView *view = [[HypnosisView alloc] initWithFrame:screenRect];
[scrollView addSubview:view];
// Move the rectangle for the other HypnosisView to the right, just off
// the screen
screenRect.origin.x = screenRect.size.width;
HypnosisView *anotherView = [[HypnosisView alloc] initWithFrame:screenRect];
[scrollView addSubview:anotherView];
// Tell the scrollView how big its virtual world is
[scrollView setContentSize:bigRect.size];
Build and run the application. Pan from left to right to see each instance of Hypnos-
isView .
 
Search WWH ::




Custom Search