Uicollectionview and UITableView mixed gesture conflicts

Source: Internet
Author: User

Objective

Recently in the reconstruction of a module, the later packaging of the so-called base class like a lump of death, see the nausea, I believe that the peers you can understand that mood. Why refactor? It is not true because it is like a lump of death, but because this module is the user most frequently used, and there are many bugs, the most important thing is this bug or P1 level of fatal bug.

Once after a few days of stress tests are not reproduced, but users frequently feedback, this is the reason for the decision to restructure. The refactoring interface is this:

When each cell in the Uicollectionview is placed in a controller.view and the Controller.view is placed in a uitableview, the scroll direction of the CollectionView is set to landscape.

However, if we set the bounces to Yes, then the right-hand return gesture is gone, what should I do?

Implementation ideas

A total of four controller classes are used:

    • Contentcontroller: Gesture conflict current controller, using Uicollectionview, each cell corresponds to a controller's view
    • SiteController1: Label a corresponding controller
    • SiteController2: The controller corresponding to the label two
    • SiteController3: label three corresponding controller
Configure Uicollectioview

123456789101112131415161718192021222324 //config collection viewuicollectionviewflowlayout *layout = [ [uicollectionviewflowlayout Alloc] Init] layout. Itemsize = Cgsizemakekscreenwidth kscreenheight -< Span class= "crayon-h" > 64 - tabviewheight layout. Scrolldirection = uicollectionviewscrolldirectionhorizontal; layout. minimumlinespacing = 0; layout. minimuminteritemspacing = 0; Self.CollectionView = [[Uicollectionview alloc] Initwithframe:cgrectmake (0 , 64 + tabviewheight kscreenwidth, Span class= "crayon-v" >kscreenheight - 64 - tabviewheight) collectionviewlayout: Layout]; [self. View addsubview: Self. CollectionView]; self. CollectionView. BackgroundColor = kwcolor; self. CollectionView. pagingenabled = YES; self. CollectionView. Showshorizontalscrollindicator = NO;   [self. CollectionView registerclass:[uicollectionviewcell class] forcellwithreuseidentifier: kpatientcellidentifier]; [self. CollectionView registerclass:[uicollectionviewcell class] forcellwithreuseidentifier: kunreadcellidentifier]; [self. CollectionView registerclass:[uicollectionviewcell class] forcellwithreuseidentifier: kallcellidentifier];       //Cannot set bounces to no, otherwise the right slip return gesture is gone//self.collectionView.bounces = NO;

When we scroll to the label three o'clock, then the slide will go out of range, it will show a part of the blank, this experience is not good, do not want to be able to slide again. Similarly, when you swipe to the tab and then right-slide, you don't want to show a blank part, but instead trigger a right-slip return gesture.

Solution Solutions

The solution is to implement the Uiscrollview proxy method, which is limited to the screen width * * When the screen width is exceeded. Similarly, when it is less than 0 o'clock, it is limited to 0, which solves the problem of whitespace. At the same time, the user response is not turned off, so the system's right-slip return gesture can still be triggered.

After such a toss, do you know how to solve the problem?

12345678910111213141516171819202122232425262728 #pragma mark--uiscrollviewdelegate- (void)scrollviewdidscroll:(uiscrollview *)ScrollView { //limit cannot exceed screen width if (scrollView. Contentoffset. X > 2 * kscreenwidth) { [scrollView setcontentoffset: Cgpointmake(2 * kscreenwidth, 0)]; return;   }   //limit cannot exceed 0   if ( Span class= "crayon-v" >scrollview. Contentoffset. X < 0 { [scrollView setcontentoffset: Cgpointmake(0, 0)]; return;   }    int Itemindex = (scrollview. Contentoffset. X +                     self. Collectionview. Hdf_width * 0.5) Span class= "crayon-h" > / selfcollectionview. Hdf_width itemIndex = itemIndex % [self collectionview: Self. CollectionView numberofitemsinsection:0];     cgfloat x = Scrollview. Contentoffset. X - selfcollectionview. Hdf_width   nsuinteger index = fabs (x) / selfcollectionview. Hdf_width cgfloat fIndex = fabs(x) /self . CollectionView. Hdf_width;    if (fabs(fIndex - (cgfloat)index) <= 0.00001) {     // .... Toggle Button   }}

Uicollectionview and UITableView mixed gesture conflicts

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.