IOS big turntable lottery, ios big Turntable

Source: Internet
Author: User

IOS big turntable lottery, ios big Turntable
Function

Click the big turntable and rotate it to a position you can determine.

Structure

Turntable, start button, pointer

Technology

CADisplayLink does not stop re-painting, CGAffineTransform rotation, simple mathematical formula

Core code

1. Use CADisplayLink to repeatedly redraw the rotating Chassis

// Start rotating (always rotating)-(void) startRotate {CADisplayLink * link = [CADisplayLink displayLinkWithTarget: self selector: @ selector (Rotate)]; [link addToRunLoop: [nsunloop mainRunLoop] forMode: NSDefaultRunLoopMode]; self. link = link;} //-(void) Rotate {// Rotate 6 ° self each time. rotateWheel. transform = CGAffineTransformRotate (self. rotateWheel. transform, M_PI * 2/12/60 );}

2. Click start to execute the rotation animation,

If (! [Self. rotateWheel. layer animationForKey: @ "zhuandong"]) {CABasicAnimation * animation = [[CABasicAnimation alloc] init]; animation. keyPath = @ "transform. rotation "; animation. toValue = @ (2 * M_PI * 5-M_PI * 2/12 * (13-self.numberIndex); animation. duration = 5; animation. removedOnCompletion = NO; animation. fillMode = kCAFillModeForwards; [self. rotateWheel. layer addAnimation: animation forKey: @ "zhuandong "]; Dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (animation. duration * NSEC_PER_SEC), dispatch_get_main_queue (), ^ {self. rotateWheel. transform = CGAffineTransformMakeRotation (M_PI * 2/12 * (13-self.numberIndex); self. link. paused = YES; [self. rotateWheel. layer removeAnimationForKey: @ "zhuandong"]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "tip" message: @ "Congratulations! Cheated !!! "Delegate: self cancelButtonTitle: @" OK "otherButtonTitles: nil, nil]; [alert show]; if (_ delegate & [_ delegate respondsToSelector: @ selector (operator :)]) {[_ delegate LuckyDrawViewDidFinishWidthIndex: self. numberIndex];} self. numberIndex = 1 ;});}

3. Use a variable to control the last stop position of the turntable.

@property (nonatomic,assign)NSInteger numberIndex;

Demo link: http://pan.baidu.com/s/1dDPimiP

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.