1: Implement delegate and DataSource modes with @protocol
#import <UIKit/UIKit.h> @protocol myviewdatasource,myviewdelegate; @interface myview:uiview< Uialertviewdelegate> @property (nonatomic,assign) id<myviewdelegate> myviewdelegate; @property (Nonatomic, Assign) id<myviewdatasource> myviewdatasource;-(void) Myshowalert; @end @protocol myviewdelegate <NSObject > @optional-(void) Alertdidpop: (MyView *) myview;-(void) Alertconfirmshow: (MyView *) MyView Clickedbuttonatindex: ( Nsinteger) Buttonindex, @end @protocol myviewdatasource <NSObject> @optional-(NSString *) Textofalert: (MyView *) MyView, @required-(Nsuinteger) Numberofitemsinmyview: (MyView *) MyView; @required @end
#import "MyView.h" @implementation myview-(void) myshowalert{ uialertview *alert = [[Uialertview alloc] initwithtitle:@ "test instance" message:@ "message" delegate:self cancelbuttontitle:@ "Cancel" otherbuttontitles:@ "OK", nil]; Alert.message = [Self.myviewdatasource textofalert:self]; [Alert show];} -(void) Didpresentalertview: (Uialertview *) alertview{ [Self.myviewdelegate alertdidpop:self];} -(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (nsinteger) buttonindex{ [self.myviewdelegate Alertconfirmshow:self Clickedbuttonatindex:buttonindex];} @end
How to use:
#import "MyView.h" @interface Viewcontroller () <MyViewDataSource,MyViewDelegate> @end
-(void) viewdidload { [super viewdidload]; MyView *MYVW = [[MyView alloc]initwithframe:cgrectmake (0, 0, +, 460)]; Myvw.myviewdatasource = self; Myvw.myviewdelegate = self; [Self.view ADDSUBVIEW:MYVW]; [Myvw Myshowalert];}
Proxy Implementation method:-(void) Alertdidpop: (UIView *) myview{ myview.backgroundcolor = [Uicolor yellowcolor];} -(NSString *) Textofalert: (MyView *) myview{ return @ "info";} -(void) Alertconfirmshow: (MyView *) MyView Clickedbuttonatindex: (nsinteger) buttonindex{ NSLog (@ "You have selected%d", Buttonindex);}
2: Animation UIView animatewithduration Use detailed
+ (void) Animatewithduration: (nstimeinterval) duration animations: (void (^) (void)) animations+ (void) Animatewithduration: (nstimeinterval) duration animations: (void (^) (void)) animations completion: (void (^) (BOOL Finished)) completion+ (void) Animatewithduration: (nstimeinterval) Duration delay: (nstimeinterval) Delay options: ( uiviewanimationoptions) options animations: (void (^) (void)) animations completion: (void (^) (BOOL finished)) completion
Duration is the duration of the animation. Animations a block of code for animation effects
Action properties can be set:
- Frame
- Bounds
- Center
- Transform
- Alpha
- BackgroundColor
- Contentstretch
For example, a view fades out of the screen, another view appears in the code
[UIView animatewithduration:1.0 animations:^{ firstview.alpha = 0.0; Secondview.alpha = 1.0;}];
Continuous animation (You can add animations to the completion code block):
[UIView animatewithduration:2.0 animations:^{ oldimageview.alpha = 0.0; Newimageview.alpha = 1.0; Imageview.center = Cgpointmake (500.0, 512.0); } completion:^ (BOOL finished) { [UIView animatewithduration:4.0 animations:^{ newimageview.center = Cgpointmake (500.0, 512.0); }]; }];
Move from top to bottom (default is upper left corner, place the value to be changed in animations):
-(UIView *) myview{ if (!_myview) { _myview=[[uiview Alloc]initwithframe:cgrectzero]; _myview.backgroundcolor=[uicolor Redcolor]; } return _myview;} -(Ibaction) Btnaction: (ID) Sender { self.myView.frame = CGRectMake (0,44, 0); [Self.view AddSubview:self.myView]; [UIView animatewithduration:0.3 animations:^{ self.myview.backgroundcolor=[uicolor Redcolor]; Self.myView.frame = CGRectMake (0,44, +); } completion:^ (BOOL finished) { }];}
rotation and scaling of 3:uiview
Label.transform = Cgaffinetransformmakerotation (*m_pi/180.0);//clockwise rotation 90 degrees Label.transform = Cgaffinetransformmakerotation (*m_pi/180.0);//clockwise rotation 180 degrees Label.transform = Cgaffinetransformmakerotation (*M_ pi/180.0);//clockwise rotation 270 degrees Cgaffinetransform transform = Label.transform;transform = Cgaffinetransformscale (transform, 2,0.5);//The front 2 means twice times the horizontal magnification, and the back 0.5 indicates a longitudinal reduction of half label.transform = transform;
iOS Development Basics-Fragmentation 25