Weekly essays-15.11.02 and essays-15.11.02

Source: Internet
Author: User

Weekly essays-15.11.02 and essays-15.11.02
New knowledge point record for one week (15.11.02) 1. Create a tableViewCell on the storyboard

Create a tableView on the storyboard. Use UITableViewController as the container, and use UIViewController as the container to drag a tableView.

When UITableViewController is used as the container, UITableViewCell can beDynamicOr yes.StaticIf it is static, the controller can not associate files. Http://m.blog.csdn.net/blog/yhc13429826359/39580763 (to be verified)

When UIViewController is a container, the cell must be dynamic and the controller must associate a file to associate the tableView object with the Controller.

Ii. UIScrollView contentSize, contentInset, and contentOffset

I thought I had enough knowledge about the attributes of scrollView. Recently, I encountered contentInset and found that I was still vague. I would like to try again here:

UIScrollView: exists as a container

ContentView: The content view, which is used to scroll the area on the scrollView. Consider it as a view for easy understanding. All views or controls added to the scrollView are added to this view. This thing does not exist, or we do not know whether it exists. At least we cannot see it. It is just a fantasy.

ContentSize: the size of the contentView, that is, the size of the rolling view.

ContentInset: display area of the contentView, or scroll area. The default value is UIEdgeInsetsZero. That is, the entire scrollView (container) is the display area by default. The so-called display area means that contentView can be rolled freely within this range.

ContentOffset: CGPonit attribute, which is the offset of the origin point in the upper left corner of the scrollView relative to the upper left corner of the contentView.

This may be a bit abstract. For example, if you put a canvas on a window, then:

ScorllView <----> window display

ContentView <----> canvas

ContentSize <----> canvas size

ContentInset <----> determines the area of the canvas displayed on the window.

ContentOffset <----> offset of the display point origin to the current position origin of the canvas

When the size of the canvas is greater than the display area, that is, the canvas is longer or wider than the display area, the canvas cannot be fully displayed in the window, in this case, the canvas can be any scroll in the display area of the window, but the canvas edge cannot cross the display area edge.

Assume that there is a scrollView with frame {0, 0, self. view. frame. size. width, self. view. frame. size. height }.

Set contentInset to UIEdgeInsetsMake (100, 0,100, 0), that is, the up and down offset is 100, then the scrollView's scroll area (display area) is {0,100, self. view. frame. size. width, self. view. frame. size. height-200 }.

Next, set the contentSize of the scrollView, that is, the size of the content view. If we set the size and height to the same size as the scrolling area or smaller than the scrolling area, the operation will not be able to scroll, in this case, the content view can be fully displayed in the rolling area. Why does it need to scroll? If the contentSize size is larger than the display area, the Operation discovery can be slide. If the width is the same as that of the rolling area and the height is 100 higher than that of the display area, the page can be rolled vertically, the maximum deviation between the scroll up and down is 100 different.

The effect of contentOffset is to specify the position where the canvas is rolled. Call method-(void) setContentOffset :( CGPoint) contentOffset animated :( BOOL) the process can be accompanied by a rolling animation.

Notes:

1. The view added to scrollView is added to contentView.

2. Set contentInset first, set contentSize, and set contentSize first, and then set the first display effect (that is, the initial effect) of contentInset. The actual effect is the same. When contentOffset is not set at the beginning, for the former, the effect displayed at the beginning is that the top edge of the content view is attached to the top edge of the scroll area. For the latter, the top edge of contentView is the top edge of scrollView. In general, the former is the result we want, so we should set contentInset first and then set contentSize at a glance.

3. Master CollectionView usage

The essence of UICollectionView is its layout. UICollectionViewFlowLayout is the layout of rectangular streams defined by the system. To discover the power of UICollectionView, you must customize the layout mode, you can define a layout class that inherits from UICollectionViewLayout.

General Usage of UICollectionView:

(1) initialize the UICollectionViewFlowLayout instance and set the response attribute. If the attribute is not written to death, that is, the attribute values of each section are different, the corresponding proxy method is called.

(2) initialize the UICollectionView instance based on the layout instance, and set properties such as proxy and data source.

(3) implement the corresponding proxy method.

Custom usage of UICollectionView (that is, the custom Layout mode ):

(1) define a layout class inherited from UICollectionView and initialize the layout class instance in the controller.

(2) initialize the UICollectionView instance based on the layout instance, and set properties such as proxy and data source.

(3) implement the corresponding proxy method.

(4) custom Layout (CORE)

The custom layout is implemented by reloading the parent class. The specific method is as follows:

(1) first,-(void) prepareLayout will be called. By default, this method does not do anything, but in its own subclass implementation, generally, this method sets the necessary layout structure and initial required parameters.

(2) then-(CGSize) collectionViewContentSize will be called to determine the size of the content view (UIScrollView concept ).

(3) Next-(NSArray *) layoutAttributesForElementsInRect :( CGRect) The rect is called to return an array containing each unit, supplemental view, and modify view layout attributes. Each layout attribute corresponds to an instance. In the method, manually call the following three methods to obtain the corresponding layout attribute:

LayoutAttributesForCellWithIndexPath: // unit layout attribute

* LayoutAttributesForSupplementaryViewOfKind: withIndexPath: // supplement the view layout attribute to be called as needed

* LayoutAttributesForDecorationViewOfKind: withIndexPath: // call the decoration view layout attribute as needed

(4) rewrite layoutAttributesForCellWithIndexPath and set layout attributes (the key to layout ). Rewrite layoutAttributesForSupplementaryViewOfKind: withIndexPath: And layoutAttributesForDecorationViewOfKind: withIndexPath:

(5)-(BOOL) shouldInvalidateLayoutForBoundsChange :( CGRect) newBounds.

Whether to refresh the layout when the border changes. NO is returned by default. If YES is returned, the layout is refreshed when the boundary changes (usually sliding), and the preceding (1) (2) (3) method is called again. Rewrite this method as needed. If you need to refresh the layout at any time during the Sliding Process, rewrite and return YES (usually used for animation implementation during the Sliding Process). If you do not have this requirement, you do not need to rewrite it.

For details, see the Demo.

 

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.