按钮,图片,瑞士国旗的升降,手势

来源:互联网 发布:孔老师淘宝美工教程 编辑:程序博客网 时间:2024/04/29 01:31
//
//  ViewController.m
//  OCGuoQi
//
//  Created by apple  on 14-7-8.
//  Copyright (c) 2014年 apple . All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
{   UIView *redView;
    UIButton *button;
    int flag;
}
@end

@implementation ViewController
            
- (void)viewDidLoad {
    [super viewDidLoad];
    redView = [[UIView alloc] init];
    redView.frame = CGRectMake(50,400,30,30);
    redView.backgroundColor = UIColor.redColor;
    [self.view addSubview:redView];
    
    UIView *whiteColor = [[UIView alloc] initWithFrame:(CGRectMake(12,6,6,18))];
    whiteColor.backgroundColor = UIColor.whiteColor;
    [redView addSubview:whiteColor];
    
    UIView *whitColor = [[UIView alloc] initWithFrame:(CGRectMake(6,12,18,6))];
    whitColor.backgroundColor = UIColor.whiteColor;
    [redView addSubview:whitColor];
   //图片的显示
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(100,200,200,200);
    [self.view addSubview:imageView];
    [imageView initWithImage:[UIImage imageNamed:@"1"]];


//按钮的创建
    button =[UIButton buttonWithType:(UIButtonTypeSystem)];
    button.frame = CGRectMake(0,100,50,50);
    [button setTitle:@"按钮" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(did) forControlEvents: UIControlEventTouchUpInside];
    [self.view addSubview:button];
  //手势的定义
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
//    [tap addTarget:self action:@selector(did)];
//    [self.view addGestureRecognizer:tap];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
-(void)did{
    NSLog(@"滴滴");
    [UIView animateWithDuration:5 animations:^{
        if (flag == 0) {
            redView.frame = CGRectMake(50,40,30,30);
            flag = 1;
        }
        else {
            redView.frame = CGRectMake(50,400,30,30);
            flag = 0;
        }
    }];


}

@end



0 0
原创粉丝点击