Basic knowledge of IOS development-fragment 39, basic knowledge of ios-39

Source: Internet
Author: User

Basic knowledge of IOS development-fragment 39, basic knowledge of ios-39

1: UIWindow knowledge point

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];    self.window.backgroundColor=[UIColor redColor];    self.window.rootViewController=[[ViewController alloc]init];    [self.window makeKeyAndVisible];    return YES;}

IOS9 requires that all uiwindows have rootViewController. If there is no rootViewController, an error is returned;

(A) self. window makekeyandvisible makes the window the main window and displays it. In this way, the information can be displayed on the screen.

(B) because the makekeyandvisible method exists in the Window, this Window can be displayed out of thin air. Other views do not have this method, so it can only depend on the Window. After the Window is displayed, view is attached to the Window.

(C) [self. window make keywindow] // make uiwindow the main window, but it is not displayed.

(D) [UIApplication sharedApplication]. the UIWindow list opened by windows in this application, so that you can access any UIView object in the application (the keyboard popped up by the input text is located in a new UIWindow)

(D) [UIApplication sharedApplication]. keyWindow (obtain the main window of the Application) is used to receive keyboard and non-touch message events. In the program, only one UIWindow is keyWindow at each time.

Tip: If a text box in a UIWindow cannot be entered, it may be because this UIWindow is not a keyWindow.

(F) view. window: Obtain the UIWindow of a UIView.

 

 

2: UINavigationController knowledge point

A. Add the sub-controller to the navigation controller in four ways

First:

1. Create a navigation Controller

UINavigationController * nav = [[UINavigationControlleralloc] init];

2. Set the navigation controller to the Root View of the window.

Self. window. rootViewController = nav;

3. Add

YYOneViewController * one = [[YYOneViewController alloc] init];

[Nav pushViewController: one animated: YES];

 

Second:

1. Create a navigation Controller

UINavigationController * nav = [[UINavigationControlleralloc] init];

2. Set the navigation controller to the Root View of the window.

Self. window. rootViewController = nav;

3. Add

YYOneViewController * one = [[YYOneViewController alloc] init];

[Nav addChildViewController: one];

 

Third:

1. Create a navigation Controller

UINavigationController * nav = [[UINavigationControlleralloc] init];

2. Set the navigation controller to the Root View of the window.

Self. window. rootViewController = nav;

3. Add

YYOneViewController * one = [[YYOneViewController alloc] init];

Nav. viewControllers = @ [one]; (Added to the stack of the navigation Controller)

Note: nav. viewControllers; = nav. childViewControllers; note that this attribute is read-only and cannot be written as follows. Nav. childViewControllers = @ [one];

 

Fourth: the most common method

YYOneViewController * one = [[YYOneViewController alloc] init];

UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController: one];

 

B. The title in the navigation bar of the current sub-Controller Interface and the settings of the corresponding return title

Self. navigationItem. title = @ "first interface ";

Self. navigationItem. backBarButtonItem = [[UIBarButtonItemalloc] initWithTitle: @ "returns a" style: UIBarButtonItemStylePlain target: nilaction: nil];

 

C. Add a button to the navigation bar

Note: You can add one or more (arrays)

Add the button on the left of the navigation bar (add a button for the camera icon ).

Self. navigationItem. leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCamera target: nil action: nil];

 

D. Interface jump

Jump to the Second Interface (currently the third, remove the Controller at the top of the current stack)

[Self. navigationController popViewControllerAnimated: YES];

Remove all controllers outside the Processing Stack Controller

[Self. navigationController popToRootViewControllerAnimated: YES];

As long as a controller in the stack is passed in, it will jump to the specified controller [self. navigationController popToViewController: <# (UIViewController *) #> animated: <# (BOOL) #>];

 

Note:

The navigation controller manages sub-controllers in the form of stacks (Advanced and later). The view displayed on the navigation controller is always the view of the stack top controller. A navigation controller has only one navigation bar, that is to say, all the self controllers share one navigation bar.

 

Appendix: print all the child controls under the current window and save them through an xml file.

// Obtain the focus of the application (representing interaction with the user)-(void) applicationDidBecomeActive :( UIApplication *) application {NSLog (@ "applicationDidBecomeActive "); UINavigationController * nav = (UINavigationController *) self. window. rootViewController; UINavigationBar * bar = nav. navigationBar; // NSLog (@ "% @", NSStringFromCGRect (bar. frame); NSString * str = [self digView: self. window]; [str writeToFile: @ "/Users/apple/Desktop/ios6.xml" atom Ically: YES];}/*** return all levels of the imported veiw. ** @ param view: view of the level structure. ** @ return string */-(NSString *) digView :( UIView *) view {if ([view isKindOfClass: [UITableViewCell class]) return @ "; // 1. initialize NSMutableString * xml = [NSMutableString string]; // 2. the tag starts with [xml appendFormat: @ "<% @ frame = \" % @ \ "", view. class, NSStringFromCGRect (view. frame)]; if (! CGPointEqualToPoint (view. bounds. origin, CGPointZero) {[xml appendFormat: @ "bounds = \" % @ \ "", NSStringFromCGRect (view. bounds)];} if ([view isKindOfClass: [UIScrollView class]) {UIScrollView * scroll = (UIScrollView *) view; if (! UIEdgeInsetsEqualToEdgeInsets (UIEdgeInsetsZero, scroll. contentInset) {[xml appendFormat: @ "contentInset = \" % @ \ "", NSStringFromUIEdgeInsets (scroll. contentInset)] ;}}// 3. determine whether to end if (view. subviews. count = 0) {[xml appendString: @ "/>"]; return xml;} else {[xml appendString: @ ">"] ;}// 4. traverse all child controls for (UIView * child in view. subviews) {NSString * childXml = [self digView: child]; [xml appendString: childXml];} // 5. end of the tag [xml appendFormat: @ "</% @>", view. class]; return xml ;}

 

 

3: UICollectionViewLayout custom knowledge point

A: First, check its open attributes and Methods. You can use the attributes to correspond to their methods. The methods are flexible.

@protocol UICollectionViewDelegateFlowLayout <UICollectionViewDelegate>@optional- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section;- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;@endNS_CLASS_AVAILABLE_IOS(6_0) @interface UICollectionViewFlowLayout : UICollectionViewLayout@property (nonatomic) CGFloat minimumLineSpacing;@property (nonatomic) CGFloat minimumInteritemSpacing;@property (nonatomic) CGSize itemSize;@property (nonatomic) CGSize estimatedItemSize NS_AVAILABLE_IOS(8_0); // defaults to CGSizeZero - setting a non-zero size enables cells that self-size via -preferredLayoutAttributesFittingAttributes:@property (nonatomic) UICollectionViewScrollDirection scrollDirection; // default is UICollectionViewScrollDirectionVertical@property (nonatomic) CGSize headerReferenceSize;@property (nonatomic) CGSize footerReferenceSize;@property (nonatomic) UIEdgeInsets sectionInset;// Set these properties to YES to get headers that pin to the top of the screen and footers that pin to the bottom while scrolling (similar to UITableView).@property (nonatomic) BOOL sectionHeadersPinToVisibleBounds NS_AVAILABLE_IOS(9_0);@property (nonatomic) BOOL sectionFootersPinToVisibleBounds NS_AVAILABLE_IOS(9_0);@end

 

B: Item size (the size of each item). You can flexibly define the size of each Item.

Layout. itemSize = CGSizeMake (30, 20 );

Or

-(CGSize) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout sizeForItemAtIndexPath :( NSIndexPath *) indexPath;

 

 

C: Line spacing (spacing of each Line)

@ Property (CGFloat) minimumLineSpacing

Or

-(CGFloat) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout minimumLineSpacingForSectionAtIndex :( NSInteger) section;

Note: this parameter is set to a small interval of each line. If the actual interval is greater than this interval, the actual interval prevails;

 

 

D: Inter cell spacing (spacing of cell items in each row)

@ Property (CGFloat) minimum InteritemSpacing

Or

-(CGFloat) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout minimumInteritemSpacingForSectionAtIndex :( NSInteger) section;

Note: It is also set to the smallest spacing. If it is larger than this, the actual spacing prevails.

 

 

E: Scrolling direction (rolling direction)

Set the scrollDirection attribute. The two values are as follows:

UICollectionViewScrollDirectionVertical

Uicollectionviewscrolldirehorhorizontal

 

 


F: Header and footer size (Header and footer size)

The following are some explanations of the header and footer.

N is supplementary views.

N provide content through the data source method, as shown below

-CollectionView: viewForSupplementaryElementOfKind: atIndexPath:

 

N constants (types)

UICollectionElementKindSectionHeader

UICollectionElementKindSectionFooter

 

N also needs to register a class and retrieve the view from the queue

-RegisterClass: forSupplementaryViewOfKind: withReuseIdentifier:

-RegisterNib: forSupplementaryViewOfKind: withReuseIdentifier:

-DequeueReusableSupplementaryViewOfKind: withReuseIdentifier: forIndexPath:

 

How to configure the size of the header and footer:

1) global configuration is supported.

@ Property (CGSize) headerReferenceSize

@ Property (CGSize) footerReferenceSize

 

2) You can also configure each section by using delegate, as shown in the following code:

-(CGSize) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout referenceSizeForHeaderInSection :( NSInteger) section;

-(CGSize) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout referenceSizeForFooterInSection :( NSInteger) section;

When it is vertical, you need to set the Height. When it is horizontal, you need to set the Width

 

G: Section Inset (Section Inset is the boundary range of cells in a section)

@ Property UIEdgeInsets sectionInset;

Or

-(UIEdgeInsets) collectionView :( UICollectionView *) collectionView layout :( UICollectionViewLayout *) collectionViewLayout insetForSectionAtIndex :( NSInteger) section;

 

Application:

            UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];            self.mediaView = [[UICustomCollectionView alloc] initWithFrame:CGRectMake(10, 10, Main_Screen_Width-2*15, 80) collectionViewLayout:layout];

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.