zoukankan      html  css  js  c++  java
  • UIScrollView的简单使用

    由于注释写的比较全面,在这我就把原码拿过来了。

    - (void)viewDidLoad

    {

        [superviewDidLoad];

        //1.创建scrollview

        UIScrollView *scrollView = [[UIScrollViewalloc]init];

        [self.view addSubview:scrollView];

        //2.创建imageview imageview添加到scrollview上进行显示,因为scrollview上不能显示图片

        NSString *imageName = [NSStringstringWithFormat:@"big.jpg"];

        UIImage *image = [UIImage imageNamed:imageName];

        UIImageView *imageview = [[UIImageViewalloc]initWithImage:image];

        //3.将图片的宽高,设置为imageview的宽高

        CGFloat imgW = imageview.image.size.width;

        CGFloat imgH = imageview.image.size.height;

        imageview.frame = CGRectMake(0, 0, imgW, imgH);

        //4.设置scrollview的可视范围

        scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

        //5.设置scrollview的内容尺寸

        scrollView.contentSize = CGSizeMake(imgW, imgH);

        //6.设置取消滚动条

        scrollView.showsHorizontalScrollIndicator = NO;

        scrollView.showsVerticalScrollIndicator = NO;

        //7.设置scrollview的额外滚动区域

        scrollView.contentInset = UIEdgeInsetsMake(10, 20, 40, 80);

        //8.设置scrollview的当前位置它的x,y值是当前显示的左上角(00

        scrollView.contentOffset = CGPointMake(200, 200);

        //9.设置scrollview的捏合手势实现(缩放),实现需要代理方法,遵循scrollviewdelegate的协议

        scrollView.delegate = self;

        //10.设置缩放的最大,最小比列

        scrollView.minimumZoomScale = 0.2;

        scrollView.maximumZoomScale = 2.0;

        _imageView = imageview;

        [scrollView addSubview:imageview];

    }

    //scrollview的代理方法,返回将要缩放的view

    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

    {

        return_imageView;

    }

  • 相关阅读:
    sql分页查询
    SQL语句优化技术分析
    大型数据库的设计原则与开发技巧
    Microsoft SharePoint Server 2010 的新增功能
    Installing SharePoint 2010 on Windows 7
    Missing the ManageContent and structure in MOSS 2010
    Simple SharePoint 2010 + Silverlight + Client Object Model Example
    SharePoint 2010 Central AdminCreate/Extend Web Application button on Ribbon are disabled
    利用SharePoint Designer 修改列表页面实例
    数据库设计中的14个技巧
  • 原文地址:https://www.cnblogs.com/yinqiang/p/3446425.html
Copyright © 2011-2022 走看看