Basic knowledge of IOS development-fragment 25, basic knowledge of ios-Fragment

Source: Internet
Author: User

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;

 

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.