zoukankan      html  css  js  c++  java
  • 相册跳转

     

           

    #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];

    }

     

    让明天,不后悔今天的所作所为
  • 相关阅读:
    Matplotlib 绘图库 基本使用方法
    linux socat命令
    linux shell重定向
    linux man命令
    bashttpd使用手册
    libcurl代码示例
    vim文件头部注释配置
    linux join命令
    iterm2切换显示屏vim乱行解决
    分形与混沌
  • 原文地址:https://www.cnblogs.com/-yun/p/4370024.html
Copyright © 2011-2022 走看看