相册跳转
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "Myimageview.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor =[UIColor orangeColor];
//如果vc是在导航里的,并且界面里只有一个是sv,sv会被自动调节。
//关闭自动调整。
//
UIScrollView *sv=[[UIScrollView alloc]initWithFrame:CGRectMake(10, 10, 300, 550)];
sv.showsVerticalScrollIndicator=NO;
for (int i=0; i<15; i++) {
Myimageview *miv=[[Myimageview alloc]initWithFrame:CGRectMake(i%3*100, i/3*150, 100, 150)];
miv.image=[UIImage imageNamed:[NSString stringWithFormat:@"2_%d.jpg",i+1]];
[miv settitle:[NSString stringWithFormat:@"Num %d",i]];
[sv addSubview:miv];
UITapGestureRecognizer *tapGR=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGR:)];
miv.userInteractionEnabled=YES;
[miv addGestureRecognizer:tapGR];
}
sv.contentSize=CGSizeMake(300, 150*5);
[self.view addSubview:sv];
}
-(void)tapGR:(UITapGestureRecognizer *)tapGR
{
SecondViewController *svc=[[SecondViewController alloc]init];
svc.tapGR = tapGR;
[self.navigationController pushViewController:svc animated:YES];
}
#import "Myimageview.h"
@implementation Myimageview
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, 15)];
view.backgroundColor=[UIColor whiteColor];
view.alpha=0.3f;
[self addSubview:view];
_titlelabel=[[UILabel alloc]initWithFrame:view.frame];
_titlelabel.font=[UIFont systemFontOfSize:10];
_titlelabel.textColor=[UIColor blackColor];
[self addSubview:_titlelabel];
}
return self;
}
-(void)settitle:(NSString *)str
{
_titlelabel.text=str;
}
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
@property (nonatomic,retain)UITapGestureRecognizer *tapGR;
@end
#import "SecondViewController.h"
#import "Myimageview.h"
@interface SecondViewController ()<UIScrollViewDelegate>
@end
@implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor cyanColor];
UITextField *tf=[[UITextField alloc]initWithFrame:CGRectMake(40, 70, 240, 25)];
tf.tag=100;
tf.borderStyle=UITextBorderStyleRoundedRect;
[self.view addSubview:tf];
UIScrollView *sv=[[UIScrollView alloc]initWithFrame:CGRectMake(30, 100, 260, 450)];
UIImageView *iv=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 260, 450)];
iv.image=[(Myimageview *)self.tapGR.view image];
iv.tag=1;
sv.delegate=self;
sv.maximumZoomScale=3;
sv.minimumZoomScale=0.5;
[sv addSubview:iv];
[self.view addSubview:sv];
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveClick)];
}
-(void)saveClick
{
UITextField *tf =(UITextField *)[self.view viewWithTag:100];
[(Myimageview *)self.tapGR.view settitle:tf.text];
[self.navigationController popViewControllerAnimated:YES];
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [scrollView viewWithTag:1];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
posted on 2014-03-26 20:53 Sinner_Yun 阅读(247) 评论(0) 编辑 收藏 举报