您的位置:首页 > 产品设计 > UI/UE

UI - UIImageView 和页面跳转

2015-08-25 21:06 513 查看
这节课做了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:^{
}];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息