UI - UIImageView 和页面跳转

这节课做了UIImageView的静态图和动态图的添加,并且添加手势,使页面跳转,下面是代码部分

#RootViewController

#import "RootViewController.h"
#import "SecondViewController.h"
@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 如果图片的名字是以png结尾 可以只写图片名 否则图片名和格式都要写出来
//    UIImage *image = [UIImage imageNamed:@"2"];
    UIImage *image = [UIImage imageWithContentsOfFile:@"/Users/lanou/Desktop/壁纸/97054020.jpg"];
    UIImageView *imageView = [[UIImageView alloc]initWithImage:(image)];
    imageView.frame = CGRectMake(10, 30, 350, 400);
    imageView.userInteractionEnabled = YES;
    [self.view addSubview:imageView];
    [imageView release];

    // 创建一个轻拍手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doTap:)];
    [imageView addGestureRecognizer:tap];
    [tap release];

    /*
    NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
    for (int i = 1; i <= 2; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"1-%d(被拖移).tiff", i]];
        [arr addObject:image];
    }
    imageView.animationImages = arr;
    [imageView setAnimationDuration:0.5];
    [imageView setAnimationRepeatCount:4];
    [imageView startAnimating];
    [self.view addSubview:imageView];
    [imageView release];
     */

}

- (void)doTap:(UITapGestureRecognizer *)tap
{
    // 通过tap.view可以获得当前手势放置在哪一个view上
//    NSLog(@"被点击了 (╯‵□′)╯︵┻━┻ FUCK NO%@", tap.view);

    //进入第二个界面
    //1>创建第二个界面
    SecondViewController *secondVC = [[SecondViewController alloc]init];
    //2>进入
    [self presentViewController:secondVC animated:YES completion:^{
    }];
    [secondVC release];
}

#SecondViewController.m

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIButton *returnButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    returnButton.frame = CGRectMake(50, 350, 80, 30);
    returnButton.backgroundColor = [UIColor yellowColor];
    [returnButton setTitle:@"返回" forState:(UIControlStateNormal)];
    [returnButton addTarget:self action:@selector(didClickRetureButtonAction:) forControlEvents:(UIControlEventTouchDragInside)];
    [self.view addSubview:returnButton];
}
#pragma mark - back
- (void)didClickRetureButtonAction:(UIButton *)button
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值