iOS parody today's headlines slide navigation

Source: Internet
Author: User

Previously wrote a blog NetEase home navigation packaging class, NetEase home navigation package optimization, today on the basis of the top two of today's headlines.

1. NetEase Home Navigation Package class mainly solves the above navigation ScrollView and the following page ScrollView linkage problem, as well as the above navigation bar cheap quantity.

2. NetEase Home Navigation packaging class optimization mainly to solve the iOS7 above the sliding return function of Uiscreenedgepangesturerecognizer and scrollview of the sliding gesture collision problem.

Today, like today's headlines sliding navigation and NetEase home navigation package class optimization Similar, this is also to resolve the gesture conflict, uipangesturerecognizer and scrollview gestures conflict.

First, the level of Viewcontroller

Described in the above diagram, the left side of the personal page Viewcontroller above through Addchildviewcontroller added a mainviewcontroller for the Rootviewcontroller

Uinavigationcontroller, add the Uinavigationcontroller view to the Viewcontroller view of the personal page by Addsubview.

Ii. imitation of today's headlines sliding navigation has 3 main questions:

1.UIPanGestureRecognizer gesture conflict with ScrollView

In order to achieve the effect of drag and slide, need to add a uipangesturerecognizer to Mainviewcontroller, because the bottom is composed of ScrollView and TableView, So will make uipangesturerecognizer with the bottom of the conflict, and NetEase home navigation package class optimization similar to need in

-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) Othergesturerecognizer returns yes according to Gesturerecognizer to make both Scrolview and Uipangesturerecognizer recognized.

2.UIPanGestureRecognizer slide End position is incorrect

Use Uipangesturerecognizer to change the position of the Uinavigationcontroller view based on the offset. At the end of today's headline, the Uinavigationcontroller view is either in-situ or on the right, not in the middle, and the question reminds me of the jelly effect I did before, the gesture state, Change the position of the Uinavigationcontroller view based on the state of the gesture, especially at the end of the gesture.

3. Since 1 Scrolview and Uipangesturerecognizer are recognized, the Scrolview will also slide when returning

Let the bottom of the Scrolview can slide time should be Uinavigationcontroller view in the initial position of frame x is 0, so in its frame x>0, the bottom of the Bottomscrollview

Scrollenabled=no.

Third, the main implementation of code (navigation code is not affixed, only the main)

1. Declaring a drag gesture

@property (Nonatomic,strong) Uipangesturerecognizer *pangesturerecognizer;

2. Add gestures for Mainviewcontroller

_pangesturerecognizer=[[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector (pangesture:)];    _pangesturerecognizer. delegate= self;    [Self.navigationController.view Addgesturerecognizer:_pangesturerecognizer];

3. Method of gesture recognition

//panning-(void) Pangesture: (uipangesturerecognizer*) pan{//position in view//cgpoint Point=[pan LocationInView:self.navigationController.view]; //The amount of movement in view is the origin of the finger pressedCgpoint point1=[Pan TranslationInView:self.navigationController.view]; if(pan.state==uigesturerecognizerstatechanged&&pan==_pangesturerecognizer) {                if(point1.x>0&&self.navigationcontroller.view.frame.origin.x<self.navigationcontroller.view.frame.size.width- -) {            floatx= self.navigationcontroller.view.frame.origin.x+point1.x>self.navigationcontroller.view.frame.size.width- -? self.navigationcontroller.view.frame.size.width- -: self.navigationcontroller.view.frame.origin.x+point1.x; Self.navigationController.view.frame=CGRectMake (x, SELF.NAVIGATIONCONTROLLER.VIEW.FRAME.ORIGIN.Y, Self.navigationController.view.frame.size.width            , self.navigationController.view.frame.size.height); NSLog (@"%@", Nsstringfromcgrect (self.navigationController.view.frame)); }        Else if(point1.x<0) {NSLog (@"AAA%f", self.navigationcontroller.view.frame.origin.x); floatx=self.navigationcontroller.view.frame.origin.x+point1.x<0?0: self.navigationcontroller.view.frame.origin.x+point1.x; Self.navigationController.view.frame=CGRectMake (x, SELF.NAVIGATIONCONTROLLER.VIEW.FRAME.ORIGIN.Y, Self.navigationController.view.frame.size.width        , self.navigationController.view.frame.size.height); }    }    Else if(pan.state==uigesturerecognizerstateended) {        if(self.navigationcontroller.view.frame.origin.x>self.navigationcontroller.view.frame.size.width/3) {[UIView animatewithduration:0.2animations:^{self.navigationController.view.frame=cgrectmake (self.navigationcontroller.view.frame.size.width- -,0, Self.navigationController.view.frame.size.width, self.navigationController.view.frame.size.height); } Completion:^(BOOL finished) {self.bottomScrollView.scrollEnabled=YES;        }]; }        Else{[UIView animatewithduration:0.2animations:^{self.navigationController.view.frame=cgrectmake (0,0, Self.navigationController.view.frame.size.width, self.navigationController.view.frame.size.height); } Completion:^(BOOL finished) {self.bottomScrollView.scrollEnabled=YES;                    }]; }    }    //The offset is incremented should be set to 0[Pan Settranslation:cgpointzero InView:self.navigationController.view];}

4. Gesture Conflict Resolution

-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) othergesturerecognizer{if(self.bottomscrollview.contentoffset.x<=0.0&&gesturerecognizer==_pangesturerecognizer) {        if(self.navigationcontroller.view.frame.origin.x>0) {self.bottomScrollView.scrollEnabled=NO; }        Else{self.bottomScrollView.scrollEnabled=YES; }        returnYES; }    returnNO;}

Four

iOS parody today's headlines slide navigation

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.