IOS Lottery Turntable

Source: Internet
Author: User
#import "ViewController.h" @interface Viewcontroller () {NSString *strprise;}
@property (Retain, nonatomic) UIView *popview;
@property (Retain, nonatomic) Uilabel *labprise;
@property (Retain, nonatomic) UIButton *btn;

@property (Retain, nonatomic) Uiimageview *zhuanpan;

@end @implementation Viewcontroller @synthesize btn;

    -(void) viewdidload {[Super viewdidload]; Background Uiimageview *IMGVIEWBG = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, Self.view.frame.size.width, Self.vie
    W.frame.size.height)];
    Imgviewbg.image = [UIImage imagenamed:@ "Bg.png"];

    [Self.view ADDSUBVIEW:IMGVIEWBG];
    Turntable _zhuanpan = [[Uiimageview alloc] Initwithframe:cgrectmake ((self.view.frame.size.width-280)/2,10, 280, 280)];
    _zhuanpan.image = [UIImage imagenamed:@ "Zhuanpan.png"];

    [Self.view Addsubview:_zhuanpan];
    Finger Uiimageview *hander = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, 40, 40)]; Hander.center = Cgpointmake (_zhuanpan.center.x, _zhUANPAN.CENTER.Y-30);
    Hander.image = [UIImage imagenamed:@ "Hander.png"];

    [Self.view Addsubview:hander]; _labprise = [[Uilabel alloc] Initwithframe:cgrectmake (Cgrectgetminx (_zhuanpan.frame), Cgrectgetmaxy (_zhuanpan.frame
    ) +50, Cgrectgetwidth (_zhuanpan.frame), 20)];
    _labprise.textcolor = [Uicolor Orangecolor];
    _labprise.textalignment = Nstextalignmentcenter;

    [Self.view addsubview:_labprise]; Start or stop button btn = [[UIButton alloc] Initwithframe:cgrectmake ((self.view.frame.size.width-200)/2, Cgrectgetmaxy (_
    Labprise.frame) +50, 200, 35)];
    [Btn addtarget:self Action: @selector (Btnclick) forcontrolevents:uicontroleventtouchupinside];
    [Btn settitle:@ "Start" forstate:uicontrolstatenormal];
    [BTN Setbackgroundcolor:[uicolor Orangecolor]]; Btn.layer.borderColor = [Uicolor Orangecolor].
    Cgcolor;
    Btn.layer.borderWidth = 1.0f;
    Btn.layer.cornerRadius = 5.0f;
    Btn.layer.masksToBounds = YES;
[Self.view ADDSUBVIEW:BTN]; }-(void) Btnclick {NsintegER angle;

    Nsinteger randomnum = Arc4random ()%100;
        if (randomnum>=91 && randomnum<=99) {angle = 300;
    Strprise = @ "First prize";
        else if (randomnum>=76 && randomnum<=) {angle = 60;
    Strprise = @ "Second Prize";
        else if (randomnum >=51 && randomnum<=75) {angle = 180;
    Strprise = @ "Third prize";
        else {angle = 240;
    Strprise = @ "No jackpot";
    [Btn settitle:@ "Lottery ..." forstate:uicontrolstatenormal];
    _labprise.text = [NSString stringwithformat:@ "Winning results:%@", @ "Waiting for lottery results"];


    btn.enabled = NO;
    cabasicanimation* rotationanimation;
    Rotationanimation = [cabasicanimation animationwithkeypath:@ "Transform.rotation.z"];
    Rotationanimation.tovalue = [NSNumber numberwithfloat:angle*m_pi/180];
    Rotationanimation.duration = 1.0f;
    Rotationanimation.cumulative = YES;

    Rotationanimation.delegate = self; The following two lines are set to keep the position unchanged after the move Rotationanimation.fillmode=kcafillmodEforwards;

    Rotationanimation.removedoncompletion = NO;
[_zhuanpan.layer addanimation:rotationanimation forkey:@ "Rotationanimation"];
                     }//Animation end-(void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag {[UIView animatewithduration:2.0 animations:^{_popview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, self.view.fr
                         Ame.size.width, Self.view.frame.size.height)];
                         _popview.backgroundcolor = [Uicolor Clearcolor];
                         _popview.transform = Cgaffinetransformmakescale (2, 2);

                         [Self.view Addsubview:_popview]; Uiimageview *popimageview = [[Uiimageview alloc] Initwithframe:cgrectmake (M, self.view.frame.size.width-200,
                         SELF.VIEW.FRAME.SIZE.WIDTH-200)];
                         Popimageview.image = [UIImage imagenamed:@ "Prise.png"];

                     [_popview Addsubview:popimageview];
             }        completion:^ (BOOL finished) {[_popview Removefromsuperview];
                         _labprise.text = [NSString stringwithformat:@ "Jackpot Result:%@", strprise];
                         [Btn settitle:@ "Start the Lottery" forstate:uicontrolstatenormal];

                     btn.enabled = YES;

}];
 } @end

Effect Chart:

Demo download

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.