Objective-c Draw Turntable (original)

Source: Internet
Author: User

I. Description

The turntable is composed of four parts, the chassis, rotating disk, turntable hands, Start button, all affixed to the Self.view, another 12 show the winning level of uilabel affixed to the rotating disc,  Animations are implemented using the Cabasecanimation class.

Second, the code

@interfaceAviewcontroller () {UIButton*Centerbutton;    Cgaffinetransform Rotatepointview; Uiimageview*Pointview; Uiimageview*Backimageview; Uiimageview*Secondimageview; Uiimageview*ImageView; /*Animation*/cabasicanimation*Animationsecond; Cabasicanimation*AnimationPoint;}@end@implementationAviewcontroller- (void) viewdidload{[Super Viewdidload]; ImageView=[[uiimageview Alloc]initwithframe:cgrectmake (device_width/2-(device_width*0.97/2), device_height/2-(device_width*0.97/2), device_width*0.97, device_width*0.97 )];    [ImageView Setbackgroundcolor:[uicolor Clearcolor]; Imageview.image=[uiimage imagenamed:@"Luckybasebackground"];         [Self.view Addsubview:imageview]; Secondimageview=[[uiimageview Alloc]initwithframe:cgrectmake (device_width/2-(device_width*0.92/2), device_height/2-(device_width*0.92/2), device_width*0.92, device_width*0.92 )];    [Secondimageview Setbackgroundcolor:[uicolor Clearcolor]; Secondimageview.image=[uiimage imagenamed:@"Luckyrotatewheel"]; Secondimageview.center=Imageview.center; Animationsecond= [Cabasicanimation Animationwithkeypath:@"transform.rotation.z"]; Animationsecond.duration=7; Animationsecond.repeatcount=1; Animationsecond.fromvalue= [NSNumber numberwithfloat:0.0];//Starting AngleAnimationsecond.tovalue = [NSNumber numberwithfloat: -* M_PI];//End Angle[Self.view Addsubview:secondimageview]; Nsarray*[email protected][@"First Prize",@"missed",@"Second prize",@"Third Prize",@"four-level award",@"Five-Equal prize",@"missed",@"Six Prize",@"Seven-Equal prize",@"Eight Prize",@"Ninth Prize",@"10 Prize"];  for(intI=0;i< encouragearray.count;i++) {UILabel*titlelabel=[[uilabel Alloc]initwithframe:cgrectmake (secondimageview.frame.size.width/2- the, secondimageview.frame.size.height/2-secondimageview.frame.size.height/2, -, SecondImageView.frame.size.height)]; Titlelabel.backgroundcolor=[Uicolor Clearcolor]; Titlelabel.text=[Encouragearray objectatindex:i]; Titlelabel.textcolor=color (193,Ten,7); Titlelabel.textalignment=Nstextalignmentcenter; Cgaffinetransform Rotatetitle= Cgaffinetransformmakerotation (m_pi*0.1663*i); Titlelabel.transform=Rotatetitle; Titlelabel.font=[uifont systemfontofsize:Ten]; TitleLabel.layer.anchorPoint=cgpointmake (0.5,0.85);            [Secondimageview Addsubview:titlelabel]; } Pointview=[[uiimageview Alloc]initwithframe:cgrectmake ( -, $, at, -)]; Pointview.center=Secondimageview.center; UIImage*imagexx=[uiimage imagenamed:@"luckyrototeselected"]; Pointview.image=Imagexx; PointView.layer.anchorPoint=cgpointmake (0.5,1); Rotatepointview= Cgaffinetransformmakerotation (m_pi*0.1663*0 );     [Pointview Settransform:rotatepointview];        [Self.view Addsubview:pointview]; AnimationPoint= [Cabasicanimation Animationwithkeypath:@"transform.rotation.z"]; Animationpoint.duration=7; Animationpoint.repeatcount=1; Animationpoint.fromvalue= [NSNumber numberwithfloat:0.0];//Starting AngleAnimationpoint.tovalue = [NSNumber numberwithfloat:- -* M_PI];//End AngleAnimationPoint.Delegate=Self ; Centerbutton=[UIButton Buttonwithtype:uibuttontypecustom]; [Centerbutton Setframe:cgrectmake (0,0, device_width*0.2, device_width*0.2)]; [Centerbutton setimage: [UIImage imagenamed:@"luckycenterbuttonpressed"] Forstate:uicontrolstatenormal]; [Centerbutton setimage: [UIImage imagenamed:@"Luckycenterbutton"] forstate:uicontrolstateselected];    [Centerbutton Settintcolor:[uicolor Clearcolor]; Centerbutton.selected=YES; Centerbutton.adjustsimagewhenhighlighted=NO; Centerbutton.backgroundcolor=[Uicolor Clearcolor];   [Centerbutton addtarget:self Action: @selector (Beginrotationclick:) forcontrolevents:uicontroleventtouchupinside]; Centerbutton.center=Imageview.center;            [Self.view Addsubview:centerbutton]; }-(void) Beginrotationclick: (ID) sender{[Centerbutton removetarget:self Action: @selector (Beginrotationclick:) forControlEvents:    UIControlEventTouchUpInside]; [Centerbutton setimage: [UIImage imagenamed:@"luckycenterbuttonpressed"] Forstate:uicontrolstatenormal]; [Centerbutton setimage: [UIImage imagenamed:@"luckycenterbuttonpressed"] forstate:uicontrolstateselected]; [Pointview.layer addanimation:animationpoint Forkey:@"Rotate-layer"]; [Secondimageview.layer addanimation:animationsecond Forkey:@"Rotate-layer"]; [Imageview.layer addanimation:animationsecond Forkey:@"Rotate-layer"]; }/*It's an agent .*/- (void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag{[pointview.layer removeanimationforkey:@"Rotate-layer"]; [Secondimageview.layer Removeanimationforkey:@"Rotate-layer"]; [Imageview.layer Removeanimationforkey:@"Rotate-layer"]; [Centerbutton setimage: [UIImage imagenamed:@"luckycenterbuttonpressed"] Forstate:uicontrolstatenormal]; [Centerbutton setimage: [UIImage imagenamed:@"Luckycenterbutton"] forstate:uicontrolstateselected]; //2 7       intValue = (arc4random ()% -) +1; if(value<= A&&value!=2&&value!=7) {Rotatepointview= Cgaffinetransformmakerotation (m_pi*0.1663*value); Pointview.transform=Rotatepointview;        [Centerbutton addtarget:self Action: @selector (Beginrotationclick:) forcontrolevents:uicontroleventtouchupinside]; return; }    if(value> A) {Nsarray*[email protected][@"2",@"7"]; intValue = (arc4random ()%2) +0; Rotatepointview= Cgaffinetransformmakerotation (m_pi*0.1663*[[Tempindexarray objectatindex:value]intvalue]); } pointview.transform=Rotatepointview; [Centerbutton addtarget:self Action: @selector (Beginrotationclick:) forcontrolevents:uicontroleventtouchupinside];}-(void) Animationdidstart: (Caanimation *) anim{}

Second, the effect

Objective-c Draw Turntable (original)

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.