Basic knowledge of IOS development-fragment 25, basic knowledge of ios-Fragment
1: Use @ protocol to implement the delegate and datasource Modes
#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
Usage:
#import "myView.h"@interface ViewController ()<MyViewDataSource,MyViewDelegate>@end
- (void)viewDidLoad { [super viewDidLoad]; myView *myVw = [[myView alloc]initWithFrame:CGRectMake(0, 0, 320, 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 @ "";}-(void) alertConfirmShow :( myView *) myView clickedButtonAtIndex :( NSInteger) buttonIndex {NSLog (@ "you selected % d", buttonIndex );}
2: Use of animation UIView animateWithDuration
+ (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 animation duration. Animation effect code block
Configurable Action attributes:
- Frame
- Bounds
- Center
- Transform
- Alpha
- BackgroundColor
- ContentStretch
For example, if a view fades out of the screen and another view shows Code
[UIView animateWithDuration:1.0 animations:^{ firstView.alpha = 0.0; secondView.alpha = 1.0;}];
Continuous animation (you can add an animation 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); }]; }];
From top to bottom (the default is the upper left corner, and the value to be changed is placed 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, 320, 0); [self.view addSubview:self.myView]; [UIView animateWithDuration:0.3 animations:^{ self.myView.backgroundColor=[UIColor redColor]; self.myView.frame = CGRectMake(0,44, 320, 100); } completion:^(BOOL finished) { }];}
3: rotation and scaling of UIView
Label. transform = CGAffineTransformMakeRotation (90 * M_PI/180.0); // rotate the label 90 degrees clockwise. transform = CGAffineTransformMakeRotation (180 * M_PI/180.0); // rotate the label 180 degrees clockwise. transform = CGAffineTransformMakeRotation (270 * M_PI/180.0); // rotate 270 degrees CGAffineTransform transform = label clockwise. transform; transform = CGAffineTransformScale (transform, 2, 0.5); // The front 2 represents a horizontal enlargement of 2 times, and the back 0.5 represents a vertical reduction of half of the label. transform = transform;