Iphone/ipad size, frame and bounds summary and UIScroll view study notes, iphone ipad
1. iphone/ipad size
| Device |
Screen dimensions (in points) |
| Iphone and ipod |
320X480 |
| Ipad |
768X1024 |
2. UIScreen bounds and applicationFrame
[UISCreen mainScreen]. bounds, always returns the width/height in portait mode, that is, width: 320 height: 480 for iPhone
[UISCreen mainScreen]. applicationFrame is more complex. It takes the height of the status bar into consideration.
Portait mode, x: 0, y: 20, width: 320, height: 460
Landscape, x: 20, y: 0, width: 300, height: 480
For the differences between frame and bounds, see the differences between the frame and bounds attributes in UIView.
3. status bar height: 20, tool bar height: 44, tab bar height: 44
4. UIScrollView
- ContentSize and contentInSet
The position of the vertices visible in the upper left corner of the current scroll view in the content view. You can control the vertices in the code to scroll the scroll view. for example, if a view contains many text fields, the text field may be hidden when displayed on the keyboard. Therefore, we need to roll the text field scroll to the visible area. As shown in:
// Called when the UIKeyboardDidShowNotification is sent. -(void) keyboardWasShown :( NSNotification *) aNotification {NSDictionary * info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey: UIKeyboardFrameBeginUserInfoKey] CGRectValue]. size; UIEdgeInsets contentInsets = UIEdgeInsetsMake (0.0, 0.0, kbSize. height (0.0); scrollView. contentInset = contentInsets; scrollView. scrollIndicatorInsets = ContentInsets; // If active text field is hidden by keyboard, scroll it so it's visible // Your application might not need or want this behavior. CGRect aRect = self. view. frame; aRect. size. height-= kbSize. height; if (! CGRectContainsPoint (aRect, activeField. frame. origin) {// determine whether the text field is in the visible area CGPoint scrollPoint = CGPointMake (0.0, instance); // calculate the length of scroll, assume that the instance is the calculated result. [ScrollView setContentOffset: scrollPoint animated: YES] ;}}
- UIScroll view uses paging Mode
The original Article is from here. Here we will introduce several key content:
1. Set pagingMode to YES.
2. contentSize is the total width of all pages. For example, if you want to display 100 pages, the width of contentSize is 100 * scroll. frame. size. width.
3. Set showsHorizontalScrollIndicator and showsVerticalScrollIndicator to NO.
Then we need to implement scrollViewDidScroll in the delegate of scroll view. This method is called when the contentOffSet of scroll view changes. The core idea of the page flip mode is to create a view when the scroll view needs to display the next page, prepare the data on the view, and then add the view to the current position of the scroll view.
The Code is as follows. In addition, we can improve the Code by displaying the content on the next page before turning pages. Otherwise, there will be a half-black screen.
-(Void) loadPageView :( NSUInteger) page {UIView * view = [[UIView alloc] init]; view. backgroundColor = [UIColor whiteColor]; CGRect rc = self. view. frame; rc. origin. y = 0; rc. origin. x = page * self. view. frame. size. width; // create a view and adjust the x straight, because the other straight and scroll views are the same view. frame = rc; UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (0, 20, rc. size. width, 40)]; label. text = [NSString stringWithFormat: @ "current page is: % d", page]; [view addSubview: label]; [(UIScrollView *) self. view addSubview: view];}-(void) scrollViewDidScroll :( UIScrollView *) scrollView {if (scrollView. contentOffset. x> = (myCurrentPage + 0.5) * self. view. frame. size. width) // the next page needs to be displayed {myCurrentPage ++; [self loadPageView: myCurrentPage] ;}}