A multi-choice control of the iOS drive-Drawing (ii)

Source: Internet
Author: User

Then we'll write: Typeselectview

This is relatively simple, we just need each typeview position, and then as our own subview is good

@interface Typeselectview:uiview@property (nonatomic) BOOL Bshown; @property (nonatomic, Strong) typeview* curselectedview;-(ID) initWithFrame: (CGRect) frame searchtype: (int) type; @end

-(ID) initWithFrame: (CGRect) frame searchtype: (int) type{self = [super Initwithframe:frame];        if (self) {_bshown = NO;        Self.backgroundcolor = [Uicolor Clearcolor];        CGRect RCBG = frame;        RCBG.ORIGIN.Y = 0.0f;        rcbg.origin.x = 0.0f;        Uiimageview *bgimageview = [[Uiimageview alloc] INITWITHFRAME:RCBG];        Bgimageview.image = [UIImage imagenamed:@ "Change_icon_bg.png"];                [Self addsubview:bgimageview];        CGRect Typerc =cgrectmake (4.0f, 0.0f, Typeview_width, typeview_height);            for (int i = 0; i < 4; i++) {Typeview *curtypeview = [[Typeview alloc] INITWITHFRAME:TYPERC];            Curtypeview.typesview = self;            Curtypeview.typeid = i;                if (i = = type) {curtypeview.bselected = YES;            Self.curselectedview = Curtypeview;                        } [self Addsubview:curtypeview];               if (i = = 3) {typerc.origin.x = 4.0f; TYPERC.ORIGIN.Y = 78.0f;            }else {typerc.origin.x + = 314.0F/4;     }}} return self;}


Then we write Topbarview.
@interface topbarview:uiview-(void) layoutviews; @property (Nonatomic,strong) topbarcontrollerviewcontroller* Myviewcontroller; @property (nonatomic) uibutton* button; @property (nonatomic) uitextfield* TextField; @property ( Nonatomic, Strong) Typeselectview *toptypesview;-(void) onclick; @end

The code to add Typeselectview is:

-(void) layoutviews{     self.clipstobounds = YES;    _toptypesview.bshown = NO;        typeselectview* Tmptype = [[Typeselectview alloc] Initwithframe:[[homepageuimanager sharedinstance]       Searchtypesoriginframe] searchtype:0];    _toptypesview.autoresizingmask = Uiviewautoresizingflexibleleftmargin |    Uiviewautoresizingflexiblewidth | Uiviewautoresizingflexiblerightmargin;    _toptypesview = Tmptype;    So write _toptypesview in the back of these view   [[Myviewcontroller sharedinstance].view Insertsubview:_toptypesview BelowSubview : Self];

This adds the _toptypesview to[Myviewcontroller Sharedinstance].view behind, so that the initial position can be topbarview obscured, the initial position of _toptypeview is:

-(CGRect) Searchtypesoriginframe{return CGRectMake (0.0f, 44.0f-80.0f, 320.0f, 80.0f);}


The show's location is:

-(CGRect) Searchtypesshowframe{return CGRectMake (0.0f, 44.0f, 320.0f, 80.0f);}


The code for show Typeselectedview is to change the _toptypesview frame,hide is to turn the frame upside down

-(void) Toshowtypesview {    _toptypesview.frame = [[Homepageuimanager sharedinstance] searchtypesoriginframe];[ UIView beginanimations:@ "ShowTypes" context:null]; [UIView setanimationduration:0.4f]; [UIView setanimationdelegate:self]; [UIView setanimationdidstopselector: @selector (animationDidStop:finished:context:)]; [UIView Setanimationbeginsfromcurrentstate:yes]; [UIView setanimationcurve:uiviewanimationcurveeaseinout];    _toptypesview.bshown = Yes;_toptypesview.frame = [[Homepageuimanager sharedinstance] searchtypesshowframe];        [UIView commitanimations];}

Initialization of the Myviewcontroller:

-(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [Super Initwithnibname:nibnam    Eornil Bundle:nibbundleornil]; if (self) {//Custom initialization <strong>//self.view.backgroundColor = [Myviewcontroller Rgbcolorf    romhexstring:@ "#eeeeee" alpha:1.0f];//special attention do not add this sentence, if added will make Myviewcontroller to execute Viewdidload will cause the program crashes </strong>} return self;} Single example of the wording + (Myviewcontroller *) sharedinstance{static Myviewcontroller *_sharedinstance = nil;if (_sharedInstance = nil) _ Sharedinstance = [[Myviewcontroller alloc] Initwithnibname:nil bundle:nil];return _sharedinstance;}    -(void) viewdidload{[Super Viewdidload];        Do any additional setup after loading the view.    CGRect Rcsearchbar = [[Homepageuimanager sharedinstance] searchbarviewframe];    Topbarview *tmpview = [[Topbarview alloc] initwithframe:rcsearchbar];    [Tmpview Layoutviews];        [Self.view Addsubview:tmpview]; uiview* view = [[UIView alloc] Initwithframe:cgrectmAke (0, 44, 320,2)];    View.backgroundcolor = [Uicolor Graycolor];    [Self.view Addsubview:view]; }

Code can be downloaded in http://download.csdn.net/detail/baidu_nod/7644329

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.