9. Custom Flow Layout
The difference between 9.0UICollectionView and UITableView: In the layout (UITableView inherit uisorllview), Uicollectionview without setting contentsize
9.0UICollectionView the same point as UITableView: Recycling
9.1.0UICollectionView Note: 1. Initialization must be passed into the layout, (Flow layout: nine Gongge layout) 2.UICollectionViewCell must be registered 3. You must customize the cell
9.1.1 Create a pipelining layout: size itemsize (item equivalent to cell), scrolling direction scrolld, extra scrolling area Sectioni, line spacing Mini This is the setting of the flow layout inside
9.1.2 Create Uicollectionview, set dimensions, load nib to set background color, customize cell to add a UIImage property to the cell
9.2 Customizing the layout of the Uicollectionview, learn about 5 ways
1.-(void) preparelayout (function: Calculates all cell layouts, conditions: cell layout fixed, call time: When the layout starts and when the Uicollectionview is refreshed)
2.-(Nullable nsa<__kindof):(CGRect) rect (function: Returns each cell layout, allowing all cell layouts to be returned at once)
3.-(BOOL) Shouldi: () newbounds (whether to allow new layouts when dragging)
4.-(cgpoint) Target offset: (cgpoint) Velocity (function returns the final offset, call time: When the finger is away)
5.-(cgsize) CollectionView (function: Set COLLECTIONV scroll range)
9.2.1 can give the center picture Square Big
1. In the 2nd method set the distance center the closer the larger the size
2. In the 4th method, set the photo closer to the center and automatically put that picture in the center.
10.block in-depth research
10.0 about the agent, modal to send a value to the VC, to get the VC object, let VC become modal agent, after the transfer of value according to the agent method
10.1block Basic use: Save a piece of code, not immediately execute, need to manually call Inlineblock quickly generate block code
10.2block4 type of use: through block (); call
1.block declaration: Return value (^block variable name) (block parameter type), parameter variable name can be omitted
void (^block2) () or void (^BLOCK1) (int);
2.block definition: Right of equal sign ^ (parameter parameter variable name) {} (with no return value)
void (^BLOCK2) (int a) = ^ (int a) {};
3.block definition Two: right of equals ^ return value (parameter type parameter variable name) (with parameter return value)
Int (^BLOCK3) (int a) =^int (int a) {return;};
4.block definition Three: No return value, no parameters, can be omitted (no parameter, no return value)
void (^BLOCK4) () = ^{};
10.2block Development Usage Scenario (block is called to use the content)
1. Use in the same file: Declare a block with strong that has no parameters, and invoke it in different ways through this property
2. Use in different files: in the model declaration block, to Uitableviewdelegate to select the call, specific problems specific analysis
3 Pass value:. Declares a block property with Parameters 2. Block is defined in the required parameter controller, and parameter 3 is passed in the attribute. Call block in the value controller
*10.3block Memory Management (interview: Block is OC object, go to the official documents to find: Working with blocks, which wrote blocks is Object-c objects)
1. Memory 5 zones: heap, stack, method area, constant area, global zone.
2. How to differentiate Arc,mrc:arc in dealloc you cannot call [super Dealloc] to see if you can call release
3.MRC Features: manual memory management, you need to free up memory, development habits: Access properties or set properties, must use dot syntax, do not use underscores
4.MRC has no strong and weak attributes, there are assign (quite with weak), retain (quite with strong), copy
5.MRC How to manage block:block when placed in an external local variable or when static is modified, placed in the stack, other times in the global zone (Arc:block placed in the heap when the external local variable)
6.MRC NOTE: You cannot declare block with retain, he is placed in the stack and can only be placed in the heap with copy
7.ARC How to manage blocks: External local variables, placed in the heap:
8.ARC Note: Using strong to declare a block, you cannot use weak: If you do not have a strong pointer, you will destroy it.
*10.4block Circular references (block strong references to external strong pointers, not strong references to weak pointers)
1. Principle: MODVC The strong pointer to the modal object (each object has a block), the block of the modal object will point to the Block object, block object blocks when using self, will also refer back to the block in the modal object
2. Solution: Use __weak type (self) weakself = self; When a strong pointer is replaced with a weak pointer, the block that points to the modal block of the Block object is replaced with a weak pointer when self is called, and the other is destroyed when one is destroyed. .
3. Note: There is also a more difficult, when using deferred or asynchronous tasks, you need to make a strongself instead of self, and then a weak pointer outside so that they will not be destroyed and not circular references.
Flow layout and block in-depth study