Anatomy of iOS Development "secret" app content page effect (ii)

Source: Internet
Author: User

@ A few days ago wrote a "secret" cell effect article, but with the work in the desired effect or there is a gap, and extensibility is not good, so rewrite the package, the overall view is put into the scrollview, basically is the same effect as the secret app.

The @ code is as follows: (the fuzzy effect of the class will not write, you can search "uiimage+imageeffects", but also to import accelerate.framework)

1.mtsecretappeffect.h

#import <Foundation/Foundation.h> @interface mtsecretappeffect:nsobject/** *  Create a whole scrollview, Load the Headscrollview and TableView all on top, swipe up and down, the rest of the slides are all forbidden * *  @return Mainscrollview */-(Uiscrollview *) createmainscrollview;/** *  Create Headscrollview * *  @return Headscrollview */-(Uiscrollview *) createheadscrollview;/** *  Create a fuzzy view of the head * *  @param scrollview headscrollview * *  @return Blurimageview */-( Uiimageview *) Createblurimageviewofview: (Uiscrollview *) scrollview;/** *  in-(void) Scrollviewdidscroll: ( Uiscrollview *) method called in ScrollView * *  @param scrollView *  @param mainscrollview *  @param tableView *  @ Param Headscrollview *  @param blurimageview */-(void) Scrolldidscrollview: (Uiscrollview *) ScrollView Withmainscrollview: (Uiscrollview *) Mainscrollview Withtableview: (UITableView *) TableView Withheadscrollview: ( Uiscrollview *) Headscrollview Withblurimageview: (Uiimageview *) Blurimageview; @end

2.mtsecretappeffect.m

#import "MTSecretAppEffect.h" #import "uiimage+imageeffects.h" #import <QuartzCore/QuartzCore.h> #define HEADER _height 200.0f#define Header_init_frame cgrectmake (0, 0, (+), header_height) const cgfloat kbarheight = 50.0f;const CGFloa T kbackgroundparallexfactor = 0.5f;const cgfloat kblurfadeinfactor = 0.015f; @implementation mtsecretappeffect//lacking: The caller sets the proxy-(Uiscrollview *) createmainscrollview{//and self.view the same size as the bottom scrollview uiscrollview *mainscrollview = [[Uiscro]    Llview alloc] Initwithframe:[uiapplication sharedapplication].keywindow.frame];    Mainscrollview.bounces = YES;    mainscrollview.alwaysbouncevertical = YES;    Mainscrollview.contentsize = Cgsizezero;    Mainscrollview.showsverticalscrollindicator = YES;    Mainscrollview.scrollindicatorinsets = Uiedgeinsetsmake (50.0f, 0, 0, 0);    return mainscrollview; }-(Uiscrollview *) createheadscrollview{Uiscrollview *headscrollview = [[Uiscrollview alloc] Initwithframe:header_ini    T_frame]; headscrollview.scrollenabled = NO        Headscrollview.contentsize = Cgsizemake (320, 1000); return Headscrollview;} -(Uiimageview *) Createblurimageviewofview: (Uiscrollview *) scrollview{uigraphicsbeginimagecontextwithoptions (    Scrollview.bounds.size, Scrollview.opaque, 0.0);    [Scrollview.layer Renderincontext:uigraphicsgetcurrentcontext ()];    UIImage *img = Uigraphicsgetimagefromcurrentimagecontext ();    Uigraphicsendimagecontext ();    Uiimageview *blurimageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, +, header_height)]; blurimageview.image = [img applyblurwithradius:12 tintcolor:[uicolor colorwithwhite:0.8 alpha:0.4]    saturationdeltafactor:1.8 Maskimage:nil]; Blurimageview.autoresizingmask = Uiviewautoresizingflexiblewidth |    Uiviewautoresizingflexibleheight;    Blurimageview.alpha = 0;        Blurimageview.backgroundcolor = [Uicolor Clearcolor]; return Blurimageview;} -(void) Scrolldidscrollview: (Uiscrollview *) ScrollView Withmainscrollview: (Uiscrollview *) Mainscrollview Withtableview:(UITableView *) TableView Withheadscrollview: (Uiscrollview *) Headscrollview Withblurimageview: (Uiimageview *)    blurimageview{cgfloat y = 0.0f;     CGRect rect = header_init_frame;        if (Scrollview.contentoffset.y < 0.0f) {//pull-up effect y = fabs (MIN (0.0f, Mainscrollview.contentoffset.y));  Headscrollview.frame = CGRectMake (Cgrectgetminx (Rect)-y/2.0f, Cgrectgetminy (rect)-Y, Cgrectgetwidth (rect) + y,            Cgrectgetheight (rect) + y);        } else {y = Mainscrollview.contentoffset.y;        Blurimageview.alpha = MIN (1, y * kblurfadeinfactor);                CGFloat backgroundscrollviewlimit = headscrollview.frame.size.height-kbarheight; if (Y > Backgroundscrollviewlimit) {headscrollview.frame = (CGRect) {. origin = {0, y-headscrollview.frame            . Size.Height + Kbarheight},. size = {, header_height}}; Tableview.frame = (CGRect) {. origin = {0, cgrectgetminy (headscrollview.frame) + cgrectgetheight (headscrollvIew.frame)},. size = tableView.frame.size};            Tableview.contentoffset = Cgpointmake (0, Y-backgroundscrollviewlimit);            CGFloat contentoffsety =-backgroundscrollviewlimit * kbackgroundparallexfactor; [Headscrollview Setcontentoffset: (cgpoint)        {0,contentoffsety} Animated:no];            } else {headscrollview.frame = rect;            Tableview.frame = (CGRect) {. origin = {0, cgrectgetminy (rect) + cgrectgetheight (Rect)},. size = tableView.frame.size}; [TableView Setcontentoffset: (cgpoint)            {0,0} Animated:no];        [Headscrollview setcontentoffset:cgpointmake (0,-y * kbackgroundparallexfactor) animated:no]; }}} @end

3.main.m

#import "RootViewController.h" #import "CommentCell.h" #import "MTSecretAppEffect.h" #define Header_height 200.0f@interface Rootviewcontroller () <uiscrollviewdelegate, Uitableviewdatasource, UITableViewDelegate>@     Property (Nonatomic,strong) Mtsecretappeffect *secreteffect;        Secretapp Effect Object @property (Nonatomic,strong) Uiscrollview *mainscrollview;        Scrollview@property (Nonatomic,strong) Uiscrollview *headscrollview with the same size as view;         @property (Nonatomic,strong) Uiimageview *blurimageview;              @property (Nonatomic,strong) UITableView *tableview;        @end @implementation rootviewcontroller-(void) viewdidload{[Super Viewdidload];    0. Create Secretapp Effect Effect Object self.secreteffect = [[Mtsecretappeffect alloc] init];    1. Main bottom ScrollView Self.mainscrollview = [Self.secreteffect Createmainscrollview];    Self.mainScrollView.delegate = self;    Self.view = Self.mainscrollview; 2.head background View Self.headscrollview = [Self.secreteffect creatEheadscrollview];    3. Background picture view Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, +, header_height)];    Imageview.image = [UIImage imagenamed:@ "Secret.png"]; Imageview.autoresizingmask = Uiviewautoresizingflexiblewidth |    Uiviewautoresizingflexibleheight;    [Self.headscrollview Addsubview:imageview];    4. blur View _blurimageview = [Self.secreteffect CreateBlurImageViewOfView:self.headScrollView];    [Self.headscrollview Addsubview:_blurimageview]; 5.tableView Self.tableview = [[UITableView alloc] Initwithframe:cgrectmake (0, Header_height, Cgrectgetwidth (self.vi    Ew.frame), Cgrectgetheight (Self.view.frame)-style:uitableviewstyleplain];    self.tableView.scrollEnabled = NO;    Self.tableView.delegate = self;    Self.tableView.dataSource = self;    Self.tableView.tableFooterView = [[UIView alloc] Initwithframe:cgrectzero];    Self.tableView.separatorColor = [Uicolor Clearcolor]; 6. Add view [Self.view AddSubview:self.headScrollView];    [Self.view AddSubview:self.tableView]; 7. Set self.mainScrollView.contentSize = Cgsizemake (Self.tableView.contentSize.height + cgrectgetheight ( Self.headScrollView.frame));} -(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {//8. Calling method [Self.secreteffect Scrolldidscrollview:scroll View WithMainScrollView:self.mainScrollView WithTableView:self.tableView WithHeadScrollView:self.headScrollView WithBlurImageView:self.blurImageView];} #pragma mark-Hide status bar-(BOOL) Prefersstatusbarhidden {return YES;} #pragma mark-uitableview datasource-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {return 1;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section {return 20;} -(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath {return 40;} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {Commentcel L *cell = [TableView dequeuereusablecellwithidentifier:[nsstring stringwithformat:@ "Cell%ld", Indexpath.row]]; if (!cell) {cell = [[Commentcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:[nsstring StringW    ithformat:@ "Cell%ld", Indexpath.row]];    } cell.textLabel.text = [nsstring stringwithformat:@ "section =%ld row =%ld", Indexpath.section,indexpath.row]; return cell;}    -(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
@:



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.