Hmviewcontroller.m
#import "HMViewController.h"#import "HMWheelView.h"@interfaceHmviewcontroller () @property (nonatomic, weak) Hmwheelview*Wheelview;@end@implementationHmviewcontroller-(Ibaction) Start: (IDSender {[_wheelview startrotating];}-(Ibaction) Stop: (IDSender {[_wheelview stoprotating];}- (void) viewdidload{[Super Viewdidload]; //additional setup after loading the view, typically from a nib.Hmwheelview *wheel =[Hmwheelview Wheelview]; Wheel.center=Self.view.center; [Self.view Addsubview:wheel]; _wheelview=wheel; }- (void) didreceivememorywarning{[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end
hmwheelview.m
#import "HMWheelView.h"#import "HMWheelButton.h"#defineAngle2radian (x) ((x)/180.0 * M_PI)@interfaceHmwheelview () @property (weak, nonatomic) Iboutlet Uiimageview*Rotationview, @property (nonatomic, weak) UIButton*Selectedbutton, @property (nonatomic, strong) Cadisplaylink*link;@end@implementationHmwheelview+(instancetype) wheelview{return[[NSBundle Mainbundle] loadnibnamed:@"Hmwheelview"Owner:nil options:nil][0];}//and there's no connection line .- (ID) Initwithcoder: (Nscoder *) adecoder{if(self =[Super Initwithcoder:adecoder]) {NSLog (@"initwithcoder----%@", _rotationview); } returnSelf ;}//connect the line.#warningAdd button-(void) awakefromnib{_rotationview.userinteractionenabled=YES; //large picture of croppingUIImage *bigimage = [UIImage imagenamed:@"luckyastrology"]; UIImage*selectedimage = [UIImage imagenamed:@"luckyastrologypressed"]; //the size of the pictureCGFloat Imagew = +*[UIScreen Mainscreen].scale; CGFloat Imageh= -*[UIScreen Mainscreen].scale; for(inti =0; I < A; i++) { //Create buttonHmwheelbutton *button =[Hmwheelbutton Buttonwithtype:uibuttontypecustom]; //Anchor PointButton.layer.anchorPoint = Cgpointmake (0.5,1); //locationButton.layer.position = Cgpointmake (Self.bounds.size.width *0.5, Self.bounds.size.height *0.5); //Rotate buttonButton.layer.transform = Catransform3dmakerotation (Angle2radian (i * -),0,0,1); //DimensionsButton.bounds = CGRectMake (0,0, the,143); //set the background image when selected[Button Setbackgroundimage:[uiimage imagenamed:@"luckyrototeselected"] forstate:uicontrolstateselected]; //to set a picture of a button//Image: Cropped picture//rect: The size of the cropCGRect clipRect = CGRectMake (i * imagew,0, Imagew, Imageh); Cgimageref Smallimage=Cgimagecreatewithimageinrect (Bigimage.cgimage, clipRect); [Button Setimage:[uiimage imagewithcgimage:smallimage] forstate:uicontrolstatenormal]; //Set the selected pictureCgimageref Selectedsmallimage =Cgimagecreatewithimageinrect (Selectedimage.cgimage, clipRect); [Button Setimage:[uiimage imagewithcgimage:selectedsmallimage] forstate:uicontrolstateselected]; //Monitor Click events[button addtarget:self action: @selector (Btnclick:) Forcontrolevents:uicontroleventtouchdown]; if(i = =0) {[Self Btnclick:button]; } [_rotationview Addsubview:button]; }}#warningMonitor button click-(void) Btnclick: (UIButton *) button{_selectedbutton.selected=NO; Button.selected=YES; _selectedbutton=button;}#warningStart Rotation-(void) startrotating{self.link.paused=NO;}- (void) stoprotating{_link.paused=YES;}-(Cadisplaylink *) link{if(_link = =Nil) {Cadisplaylink*link =[Cadisplaylink displaylinkwithtarget:self selector: @selector (update)]; [link Addtorunloop:[nsrunloop Mainrunloop] formode:nsdefaultrunloopmode]; _link=link; } return_link;}//45/60.0- (void) update{_rotationview.transform= Cgaffinetransformrotate (_rotationview.transform, Angle2radian ( $/60.0));}-(Ibaction) Start: (ID) Sender {//1. Do not interact with users_rotationview.userinteractionenabled =NO; //2. Remove the slow rotation[self stoprotating]; Cabasicanimation*anim =[cabasicanimation animation]; Anim.keypath=@"transform.rotation"; Anim.tovalue= @ (M_PI *2*3); Anim.duration=0.5; Anim.Delegate=Self ; [_rotationview.layer Addanimation:anim Forkey:nil]; }- (void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag{_rotationview.userinteractionenabled=YES; //Let the check button return to the top middle position:CGFloat angle =atan2 (_SELECTEDBUTTON.TRANSFORM.B, _SELECTEDBUTTON.TRANSFORM.A); NSLog (@"%f", Angle); //turn our turntable in reverse so many degrees_rotationview.transform = Cgaffinetransformmakerotation (-angle); Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (2* nsec_per_sec)), Dispatch_get_main_queue (), ^{[Self startrotating]; });}@end
HMWheelView.h
#import <UIKit/UIKit.h>@interface hmwheelview:uiview+ (instancetype) Wheelview; // Start Rotation -(void) startrotating; // Stop Rotation -(void) stoprotating; @end
Hmwheelbutton.m
#import "HMWheelButton.h"@implementationHmwheelbutton//Turntable button-(CGRect) Imagerectforcontentrect: (cgrect) contentrect{cgfloat Imagew= +; CGFloat Imageh= -; CGFloat ImageX= (CONTENTRECT.SIZE.WIDTH-IMAGEW) *0.5; CGFloat Imagey= -; returnCGRectMake (ImageX, Imagey, Imagew, Imageh);}//Remove Highlight- (void) sethighlighted: (BOOL) highlighted{}@end
HMWheelButton.h
#import <UIKit/UIKit.h>@interface hmwheelbutton:uibutton@end
iOS 18th day (10, core animation-Carousel, custom Buton, rotate animation)