iOS things about landscape TableView

Source: Internet
Author: User

I've seen the TableView in the Apple Store before, and it's probably collectionview.

In particular, there is only one thing in the project that requires horizontal sliding, there is no need to use a large collectionview, embellishment of the use of a horizontal tableview instead more convenient and flexible. Of course, most of the situation here is probably using a horizontal tableview in the cell of the parent tableview.

The following is a brief introduction, based on the system native UITableView package horizontal tableview points.

When I encapsulated TableView, I used a more popular method, TableView rotation-PI/2 units of radians (that is, counterclockwise rotation 90 degrees), cell rotation PI/2 units of radians (that is, 90 degrees clockwise rotation). The end result is that the tableview becomes horizontal. There is a place in the encapsulation process that is more difficult to understand, is the horizontal tableview point problem, because the rotation, the default is to rotate with the center of the TableView, which caused the rotation of the "look" position or frame has changed, So fix this "frame deviation" due to rotation. Here, you can hold your phone, vertical placed on a vertical A4 paper, the upper left corner of the phone and A4 paper overlap the upper left corner, meaning that point is (0,0), and then you turn the phone counterclockwise 90 degrees, see what results, the result should be, the left side of the cell phone highlighted A4 part of the paper, It is also a certain distance from the top edge of the paper. So how much is this distance, should be long one-second minus the width of one-second, the specific code is this write abs (Self.bounds.size.width-self.bounds.size.height)/2, do not explain why this value, Because I don't know how to express my words, I can't find the right drawing tools. You can experience it by yourself.

So at this point the transverse tableview to the right upward offset ABS (self.bounds.size.width-self.bounds.size.height)/2 This distance is good.

The rest is the encapsulation, the implementation of the UITableView callback, UITableView must implement the callback must be implemented, and then the non-required can also be two times encapsulation, at this time can also give a default value, so that do not implement the callback when the wheel can give the default value, This looks like this:

1 -(cgfloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath { 2     if ([self.delegate_y respondstoselector: @selector (H_tableview:heightforrowatindexpath:)]) {3         return [self.delegate_y h_tableview:self Heightforrowatindexpath:indexpath]; 4     }5     return; 6 }

The callbacks that must be implemented are also posted:

1 #pragmaMark-uitableviewdatasource2-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {3     if([self.datasource_y respondstoselector: @selector (h_tableview:numberofrowsinsection:)]) {4         return[self.datasource_y h_tableview:self numberofrowsinsection:section];5     }6     return 0;7 }8 9-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {Ten     if([self.datasource_y respondstoselector: @selector (H_tableview:cellforrowatindexpath:)]) { One         return[self.datasource_y h_tableview:self Cellforrowatindexpath:indexpath]; A     } -     returnNil; -}

Do not have to look at the code is not a problem, finally I will post a coding link, you can download the source to see

Because UITableView callback, too much, I encapsulated a few, if you need more, you can imitate the implementation.

Say so much, say again the weakness of this wheel, because when using Xib or storyboard drag constraint layout of the time will cause problems, so in the code, the default comments out-(instancetype) Initwithcoder: (Nscoder *) coder. Recommend direct code write frame.

Because the cell has been rotated, the layout of the directly normal frame is OK.

Code: Https://coding.net/u/ysk/p/HorizontalTableView/git

Write to this, what is wrong or feel I write something wrong, please correct me.

iOS things about landscape TableView

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.