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

    }

     

    让明天,不后悔今天的所作所为
  • 相关阅读:
    50 个加速包都抢不到车票,还不如这个 Python 抢票神器!
    前后端开源的一款简单的微信个人博客小程序
    可以提升3倍开发效率的 Intellij IDEA快捷键大全汇总(2019)
    一张图搞定OAuth2.0
    nginx+vue实现项目动静分离
    「今日 GitHub 趋势」让全世界程序员体会中国的 12306 抢票狂潮
    C# 获取当前月第一天和最后一天
    connect to tomcat with JMX
    Java Debugging
    内存模型
  • 原文地址:https://www.cnblogs.com/-yun/p/4370024.html
Copyright © 2011-2022 走看看