UIScrollview 笔记

- (void)viewDidLoad {
    [super viewDidLoad];
    UIScrollView *tempScrollView=(UIScrollView *)self.view;
    tempScrollView.contentSize=CGSizeMake(1280,960);
}

- (void)loadView {
    CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
    scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
    scrollView.contentSize=CGSizeMake(320,758);
 
    // 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];
}

If you intend to support zoom in your scroll view, the most common technique is to use a single subview that encompasses the entire contentSize of the scroll view and then add additional subviews to that view. This allows you to specify the single ‘collection’ content view as the view to zoom, and all its subviews will zoom according to its state.

You may want to add padding around the edges of the scroll view content, typically at the top and bottom so controllers and toolbars don’t interfere with the content. To add padding, use the contentInset property to specify a buffer area around the content of the scroll view. One way of thinking of it is that it makes the scroll view content area larger without changing the size of the subview or the size of the view’s content.

UIScrollview 笔记_第1张图片
ContentSize

Setting the contentInset property

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

However, changing the contentInset value has an unexpected side effect when your scroll view displays scroll indicators. As the user drags the content to the top or bottom of the screen, the scroll indicator scrolls over any content displayed in the areas that are within the area defined by contentInset for example, in the navigation control and toolbar.

To correct this, you must set the scrollIndicatorInsets property. As with the contentInset property, the scrollIndicatorInsets property is defined as a UIEdgeInsets struct. Setting the vertical inset values restricts the vertical scroll indicators from being displayed beyond that inset and this also results in the horizontal scroll indicators being displayed outside the contentInset rect area.

Altering the contentInset without also setting the scrollIndicatorInsets property allows the scroll indicators to be drawn over the navigation controller and the toolbar, an unwanted result. However, setting the scrollIndicatorInsets values to match the contentInset value remedies this situation.

Setting the scroll view contentInset and scrollIndicatorInsets properties

- (void)loadView {
    CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
    scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
    scrollView.contentSize=CGSizeMake(320,758);
    scrollView.contentInset=UIEdgeInsetsMake(64.0,0.0,44.0,0.0);
    scrollView.scrollIndicatorInsets=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];
}

你可能感兴趣的:(UIScrollview 笔记)