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 Example"message:@"message" Delegate: Self cancelbuttontitle:@"Cancel"Otherbuttontitles:@"Determine", 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:
" myView.h " @interface Viewcontroller ()<MyViewDataSource,MyViewDelegate>@end
-(void) viewdidload { [super Viewdidload]; *MYVW = [[MyView alloc]initwithframe:cgrectmake (00-460)]; = self ; = self ; [Self.view ADDSUBVIEW:MYVW]; [Myvw Myshowalert];}
Proxy Implementation Method:-(void) Alertdidpop: (UIView *) myview{ = [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:^{ 0.0; 1.0 ;}];
Continuous animation (You can add animations to the completion code block):
[UIView animatewithduration:2.0Animations:^{Oldimageview.alpha=0.0; Newimageview.alpha=1.0; //imageview.center = Cgpointmake (500.0, 512.0);} Completion:^(BOOL finished) {[UIView animatewithduration:4.0Animations:^{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, -, the,0); [Self.view AddSubview:self.myView]; [UIView animatewithduration:0.3animations:^{Self.myView.backgroundColor=[Uicolor Redcolor]; Self.myView.frame= CGRectMake (0, -, the, -); } Completion:^(BOOL finished) {}];}
rotation and scaling of 3:uiview
Label.transform = Cgaffinetransformmakerotation ( -*M_PI/180.0);//rotate clockwise 90 degreesLabel.transform= Cgaffinetransformmakerotation ( the*M_PI/180.0);//rotate clockwise 180 degreesLabel.transform= Cgaffinetransformmakerotation ( the*M_PI/180.0);//rotate clockwise 270 degreesCgaffinetransform Transform=Label.transform;transform= Cgaffinetransformscale (Transform,2,0.5);//the previous 2 indicates a horizontal magnification of twice times, and the back 0.5 indicates a portrait reduction of halfLabel.transform= transform;
iOS Development Basics-Fragmentation 25