iOS -UI-视图创建及动画的实现

来源:互联网 发布:windows phone7.8 编辑:程序博客网 时间:2024/05/22 17:37

//

//  ViewController.m

//  UI-视图练习

//

//  Created by jzq_mac on 15/7/23.

//  Copyright (c) 2015 jzq_mac. All rights reserved.

//


#import "ViewController.h"


@interfaceViewController ()

{

    UIButton *button;

    UILabel *label;

    UITextField *textFiled;


}

@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

    self.view.backgroundColor = [UIColorblackColor];

    

    [NSTimerscheduledTimerWithTimeInterval:4target:selfselector:@selector(moveAction)userInfo:nilrepeats:YES];

    

//    UIButton 练习

    

    button = [UIButtonbuttonWithType:UIButtonTypeCustom];

    button.frame =CGRectMake(150,567, 100, 100);

    [self.viewaddSubview:button];

    button.layer.cornerRadius =50;

    button.backgroundColor = [UIColorblueColor];

//    [button setTitle:@"点我啊" forState:UIControlStateNormal];

    [buttonsetTitle:@"点我干嘛"forState:UIControlStateSelected];

    button.showsTouchWhenHighlighted =YES;

    [buttonsetTitleColor:[UIColorredColor] forState:UIControlStateNormal];

    button.titleLabel.font = [UIFontsystemFontOfSize:20];

    button.clipsToBounds =YES;

    button.contentMode =YES;

    button.alpha =0.8;

    [buttonsetTitleShadowColor:[UIColoryellowColor] forState:UIControlStateNormal];

    [buttonsetBackgroundImage:[UIImageimageNamed:@"苹果"]forState:UIControlStateNormal];

    [buttonaddTarget:selfaction:@selector(click:)forControlEvents:UIControlEventTouchUpInside];

    

   



//    UIlabel 练习

    

    label = [[UILabelalloc]initWithFrame:CGRectMake(170,70, 50, 500)];

    [self.viewaddSubview:label];

    label.backgroundColor = [UIColorredColor];

    label.text =@"梦想还是要有的 万一实现了呢";

    label.layer.cornerRadius =50;

    label.layer.masksToBounds =YES;

    label.textColor = [UIColoryellowColor];

    label.textAlignment =NSTextAlignmentCenter;

    label.font = [UIFontsystemFontOfSize:30];

    label.numberOfLines =50;


    for (int i =0; i < 2; i ++) {

        UIImageView *imgeView = [[UIImageViewalloc]initWithFrame:CGRectMake(20 + (240 + 20)*i, 587, 80,80)];

        [self.viewaddSubview:imgeView];

        imgeView.backgroundColor = [UIColorredColor];

        imgeView.layer.cornerRadius =40;

        imgeView.layer.masksToBounds =YES;

        imgeView.image = [UIImageimageNamed:@"苹果1"];

        imgeView.tag = i +100;

        }



    

    

    textFiled = [[UITextFieldalloc]initWithFrame:CGRectMake(0,0, 375,50)];

    textFiled.delegate =self;

    [self.viewaddSubview:textFiled];

    textFiled.backgroundColor = [UIColorgrayColor];

    textFiled.placeholder =@"欢迎来到星际穿越";

    textFiled.textAlignment =NSTextAlignmentCenter;

    textFiled.font = [UIFontsystemFontOfSize:30];

    textFiled.returnKeyType =UIReturnKeyDefault;

    UIImageView *left = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, 50,50)];

    left.image = [UIImageimageNamed:@"拳头"];

    textFiled.leftView = left;

    textFiled.leftViewMode =UITextFieldViewModeAlways;

    textFiled.alpha =0.5;

    

    

}


- (void)textFieldDidBeginEditing:(UITextField *)textField

{

    

}


- (void)textFieldDidEndEditing:(UITextField *)textField

{

    

}


- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    

    [textFiledresignFirstResponder];

   

    return YES;

}


- (void)moveAction

{

    //  图片移动练习

    [UIViewanimateWithDuration:2animations:^{button.frame =CGRectMake(150,0, 100,100);} completion:^(BOOL finished){[UIViewanimateWithDuration:2animations:^{button.frame =CGRectMake(150,567, 100, 100);}];}];

    

    

    

    for (int i =0; i<2; i++) {

        

        UIImageView *imgeView = (UIImageView *)[self.viewviewWithTag:i+100];

        

        if (imgeView.tag ==100) {

            

            imgeView.alpha =1;

            [UIViewanimateWithDuration:2animations:^{

                imgeView.alpha =0.0;

            }];


            [UIViewanimateWithDuration:2animations:^{

                imgeView.frame =CGRectMake(160,10, 80, 80);

            } completion:^(BOOL finished) {

                [UIViewanimateWithDuration:2animations:^{

                    imgeView.frame =CGRectMake(20,587, 80, 80);

                }];

            }];

        }else{

            

            imgeView.alpha =1;

            [UIViewanimateWithDuration:2animations:^{

                imgeView.alpha =0.0;

            }];

            [UIViewanimateWithDuration:2animations:^{

                imgeView.frame =CGRectMake(160,10, 80, 80);

            } completion:^(BOOL finished) {

                [UIViewanimateWithDuration:2animations:^{

                    imgeView.frame =CGRectMake(270,587, 80, 80);

                }];

            }];

        }

        

        

        

        

    }

    

    

    label.alpha =1;

    [UIViewanimateWithDuration:4animations:^{

        label.alpha =0.0;

    }];

    label.text =@"梦想还是要有的 万一实现了呢";

    [UIViewanimateWithDuration:3animations:^{

        label.text =@"梦想还是要有的 万一实现了呢";

    } completion:^(BOOL finished) {

        [UIViewanimateWithDuration:1animations:^{

            label.text = @"我就是我颜色不一样的花火";

        }];

    }];

    

    

    

}



- (void)click:(UIButton *)sender

{

    if (sender.selected !=YES) {

        [buttonsetBackgroundImage:[UIImageimageNamed:@"星际"]forState:UIControlStateNormal];

        [buttonsetTitle:@"点我啊"forState:UIControlStateNormal];

        sender.selected =YES;

    }else{

        [buttonsetBackgroundImage:[UIImageimageNamed:@"拳头"]forState:UIControlStateNormal ];

        [buttonsetTitle:@"点我干嘛"forState:UIControlStateSelected];

        sender.selected =NO;

    }

    

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


0 0