IOS NetEase News Home Evolution version demo (Mxsegmentedpager) with parallel head stretching

Source: Internet
Author: User

NetEase News Homepage Similar interface is simply too common, the requirements of different naturally made out of the effect is different, before

with ScrollView wrote a controller package, but there is no consideration for the controller's multiplexing and pre-adding

Loading Machine when the interface explodes, it is estimated that your app will be stuck, such as half pond

, I caught package discovery appears to preload the current interface after the three interface, so that when users swipe can see the first time

data, so The mechanism is pretty good, today to introduce a reusable framework, incidentally introduce another a Gaussian Blur

The catagory.




The three interfaces here are the most common controllers, WebView and double TableView


The framework has two uses, the first directly creates a viewcontroller to inherit it, and the second is to write the property in the controller


Here we introduce the second kind

@property (nonatomic,strong) Mxsegmentedpager *segmentedpager; //!< MX Frame




First step (create and prepare)

Create a Podfile file with your terminal, write the library you need in it, and then open the

Platform:ios, ' 7.0 '

Target ' Imageblur ' do

pod ' Mxsegmentedpager '

pod ' Sdwebimage '

pod ' Masonry '

End

If you're ready, prepare a stretched head to show the effect of the stretch and the Gaussian blur.


property to be dragged out for subsequent action



Second Step (Initialize the Framework MX)

We show three controllers, as follows, giving several properties, respectively


Super Awesome detailed remarks about how to initialize the framework

Initialize MX frame controller, header and selection bar-(void) initmx{//Head Self.segmentedpager = [[Mxsegmentedpager alloc]initwithframe:cgrectmake (0,    0, Self.view.bounds.size.width, self.view.bounds.size.height)]; Self.segmentedPager.parallaxHeader.view = Self.headview;  Note here load parallel head//Mxparallaxheadermodecenter Mxparallaxheadermodecenter Mxparallaxheadermodetop Mxparallaxheadermodebottom Four, we can test self.segmentedPager.parallaxHeader.mode = Mxparallaxheadermodefill; Parallel head Fill Mode self.segmentedPager.parallaxHeader.height = 240; Head height self.segmentedPager.parallaxHeader.minimumHeight = 64; Head min height//select Bar Controller Properties Self.segmentedPager.segmentedControl.borderWidth = 1.0; Border width Self.segmentedPager.segmentedControl.borderColor = [Uicolor Redcolor]; Border color self.segmentedPager.segmentedControl.frame = CGRectMake (0, 0, Self.view.bounds.size.width, 44); Frame Self.segmentedPager.segmentedControl.segmentEdgeInset = Uiedgeinsetsmake (0, 10, 0, 10);//Pitch self.segmented Pager.segmentedcOntrol.selectionindicatorheight = 0;//If a horizontal bar indicator is required at the bottom, 0 is gone, and//the width of the bottom indicator is based on the content Self.segmentedpager.segmentedcontrol.s    Electionstyle = Hmsegmentedcontrolselectionstyletextwidthstripe;    Hmsegmentedcontrolselectionindicatorlocationnone no bottom slide indicator required Self.segmentedPager.segmentedControl.selectionIndicatorLocation =    Hmsegmentedcontrolselectionindicatorlocationnone; self.segmentedPager.segmentedControl.verticalDividerEnabled = no;//can not scroll vertically//Fix enumeration Description width is fit to screen, not based on font Hmsegmentedco Ntrolsegmentwidthstyledynamic is the size of the font is much wider Self.segmentedPager.segmentedControl.segmentWidthStyle =        hmsegmentedcontrolsegmentwidthstylefixed; Default state Font self.segmentedPager.segmentedControl.titleTextAttributes = @{nsforegroundcoloratt                                         Ributename: [Uicolor colorwithred:153/255.0 green:153/255.0 blue:153/255.0 alpha:1],    Nsfontattributename: [Uifont systemfontofsize:14]}; Font self.segmentedpager.segmentedcontrol.s in Select StateElectedtitletextattributes = @{nsforegroundcolorattributename: [Uicolor colorwithred:2 55/255.0 green:174/255.0 blue:1 alpha:1], nsfontattributename: [Uifont Sy    STEMFONTOFSIZE:18]};        Self.segmentedPager.segmentedControlEdgeInsets = uiedgeinsetsmake (0, 0, 0, 0);    Self.segmentedPager.delegate = self;    Self.segmentedPager.dataSource = self;    [Self.view AddSubview:self.segmentedPager];     [Self.segmentedpager mas_makeconstraints:^ (Masconstraintmaker *make)         {Make.top.equalTo (self.view.mas_top). With.offset (0);         Make.left.equalTo (Self.view.mas_left);         Make.bottom.equalTo (Self.view.mas_bottom);         Make.right.equalTo (Self.view.mas_right);     Make.width.equalTo (Self.view.mas_width); }];}


Step three (proxy method)

The most important implementation of the Proxy method, respectively, is the header of the selection column and the Controller array view, the specific controller initialization can be in lazy loading

Realize

#pragma-mark <mxsegmentedpagerdelegate>-(cgfloat) Heightforsegmentedcontrolinsegmentedpager: ( Mxsegmentedpager *) segmentedpager{    //indicator bar height    return 44.0f;} #pragma-mark <mxsegmentedpagerdatasource>-(Nsinteger) Numberofpagesinsegmentedpager: (MXSegmentedPager *) segmentedpager{    //How many interfaces will be required    return 3;} -(NSString *) Segmentedpager: (Mxsegmentedpager *) Segmentedpager Titleforsectionatindex: (nsinteger) index{    // The text array of the indicator bar    return [@[@ "Controller Interface", @ "Wkwebview", @ "double tableview"] objectatindex:index];} -(UIView *) Segmentedpager: (Mxsegmentedpager *) Segmentedpager Viewforpageatindex: (nsinteger) index{    // The first one is the controller view the second is WebView the  third is a custom view this is also the most critical, by lazy loading the corresponding control of the initialization view loaded into the frame to    return [@[ Self.firstChildVC.view, Self.webview, Self.customview] objectatindex:index];}


Fourth step (the navigation bar disappears)

We need to change the navigation bar when we scroll, then there is a proxy method that needs to be implemented

When scrolling whole is called-(void) Segmentedpager: (Mxsegmentedpager *) Segmentedpager Didscrollwithparallaxheader: ( Mxparallaxheader *) parallaxheader{    //by getting scrolling corresponding view    uiscrollview *scrollview = (Uiscrollview *) Segmentedpager.subviews[0];    NSLog (@ "%lf", scrollview.contentoffset.y);    Calculate alpha value    cgfloat headalpha = (1-(-(-(SCROLLVIEW.CONTENTOFFSET.Y +)/136)) >= 0? (1-(-(SCROLLVIEW.CONTENTOFFSET.Y +)/136)): 0;    Self.headView.alpha = 1-headalpha;    if (Self.headView.alpha = = 0)    {        Self.navigationController.navigationBar.hidden = NO;    }    else    {        Self.navigationController.navigationBar.hidden = YES;    }}



Fifth step (head image stretching and Gaussian Blur)

In fact, the above four to finish the basic is almost, a demo is very simple, then we add a head, stretching to play, with a parallel head,

No play, no white.

Load head blur view picture and Avatar-(void) initheadview{//Round head without blur Self.nickImageView.layer.cornerRadius = 25.0f;    Self.nickImageView.clipsToBounds = YES;    Self.nickImageView.layer.borderColor = [[Uicolor whitecolor] cgcolor];    Self.nickImageView.layer.borderWidth = 2.0f;    __weak typeof (self) weakself = self; [Self.nickimageview sd_setimagewithurl:[nsurl urlwithstring:@ "http://twt.img.iwala.net/touxiang/ 563846208921b.jpg "] Placeholderimage:nil completed:^ (UIImage *ima GE, Nserror *error, Sdimagecachetype cachetype, Nsurl *imageurl) {if (image && CacheType = sdimagecachety            Penone) {[Weakself.nickimageview setneedsdisplay];            WeakSelf.nickImageView.alpha = 0;            [UIView animatewithduration:1.0 animations:^{weakSelf.nickImageView.alpha = 1.0f;        }];        } else {weakSelf.nickImageView.alpha = 1.0f;         }    }];   The background is blurred, the method has been in the demo, we can download to take, a method of exposure, simple can be achieved [Self.blurimageview sd_setimagewithurl:[nsurl urlwithstring:@ "http:/                                 /twt.img.iwala.net/touxiang/563846208921b.jpg "] Placeholderimage:nil completed:^ (UIImage *image, Nserror *error, Sdimagecachetype cachetype, Nsurl *imageurl) {[Self.blurimageview s                                             Etneedsdisplay];        Blur begins NSData *imagedata = uiimagejpegrepresentation (image, 0.5);                                             Fuzzy interface, the more the parameter is closer to 1, the more fuzzy, directly call him OK UIImage *blurimage = [[UIImage imagewithdata:imagedata] blurredimage:0.15f];        WeakSelf.blurImageView.image = Blurimage;            if (image && CacheType = = sdimagecachetypenone) {weakSelf.blurImageView.alpha = 0;                            [UIView animatewithduration:1.0 animations:^{weakSelf.blurImageView.alpha = 1.0f;        }];  } else {          WeakSelf.blurImageView.alpha = 1.0f;    }            }]; [Self.headview layoutsubviews];}

Gauss's internal method, which can be taken directly with

-(uiimage*) Blurredimage: (cgfloat) bluramount{if (Bluramount < 0.0 | | Bluramount > 1.0) {bluramount = 0.5    ;    } int boxsize = (int) (Bluramount * 40);        Boxsize = boxsize-(boxsize% 2) + 1; Cgimageref img = self.    Cgimage;    Vimage_buffer Inbuffer, Outbuffer;        Vimage_error Error;        void *pixelbuffer;    Cgdataproviderref inprovider = Cgimagegetdataprovider (IMG);        Cfdataref inbitmapdata = Cgdataprovidercopydata (Inprovider);    Inbuffer.width = Cgimagegetwidth (IMG);    Inbuffer.height = Cgimagegetheight (IMG);        inbuffer.rowbytes = Cgimagegetbytesperrow (IMG);    Inbuffer.data = (void*) cfdatagetbyteptr (inbitmapdata);        Pixelbuffer = malloc (Cgimagegetbytesperrow (IMG) * Cgimagegetheight (IMG));    Outbuffer.data = Pixelbuffer;    Outbuffer.width = Cgimagegetwidth (IMG);    Outbuffer.height = Cgimagegetheight (IMG);        outbuffer.rowbytes = Cgimagegetbytesperrow (IMG); Error = vimageboxconvolve_argb8888 (&inbuffer, &outbuffer, NULL, 0, 0, boxsize, boxsize, NULL, kvimageedgeextend);  if (!error) {error = vimageboxconvolve_argb8888 (&outbuffer, &inbuffer, NULL, 0, 0, boxsize, boxsize, NULL,    Kvimageedgeextend); if (error) {#ifdef DEBUG NSLog (@ "%s Error:%zd", __pretty_function__, error); #endif return    Self        } cgcolorspaceref ColorSpace = Cgcolorspacecreatedevicergb ();                                             Cgcontextref CTX = cgbitmapcontextcreate (Outbuffer.data, Outbuffer.width,                                             Outbuffer.height, 8,                                             Outbuffer.rowbytes, ColorSpace,        (cgbitmapinfo) kcgimagealphanoneskiplast);        Cgimageref imageref = Cgbitmapcontextcreateimage (CTX);        UIImage *returnimage = [UIImage imagewithcgimage:imageref]; CgcontextrelEase (CTX);        Cgcolorspacerelease (ColorSpace);    Free (pixelbuffer);        Cfrelease (Inbitmapdata);        Cgimagerelease (IMAGEREF); return returnimage;}


The usage is introduced here, very simple, and the use of TableView almost, after the initialization of directly implemented a few


Proxy method, which is very customary to use, as to how the internal reuse is implemented.


There is no more introduction, you are interested to see how the source code is to be reused



I went and forgot to introduce. There's a double-tableview show here.

The first thing we need to do is to customize a view inheritance UIView

@interface Mxcustomview () <mxpageprotocol, Uitableviewdelegate, uitableviewdatasource> @property (nonatomic, Strong) UITableView *table1; @property (nonatomic, strong) UITableView *table2; @end

Two TableView initialization and proxy method will not be expanded, you can see the demo, mainly introduce a method, so that TableView can follow the whole

Scrolling or not

#pragma mark <mxpageprotocol>-(BOOL) Segmentedpager: (Mxsegmentedpager *) Segmentedpager Shouldscrollwithview: ( UIView *) View {    //return no is represented as independent    if (view = = Self.table2) {        return no;    }    Yes is the whole    return yes;}


I almost forgot about the fun stuff.






Demo Address: Https://github.com/DeftMKJ/blur



over~~~~~~










IOS NetEase News Home Evolution version demo (Mxsegmentedpager) with parallel head stretching

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.