码迷,mamicode.com
首页 > 其他好文 > 详细

UIScrollerView 的简单使用

时间:2015-02-11 20:31:45      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

 

 

//

//  RootViewController.m

//  Lianxi_02

//

//  Created by Super man on 15-2-11.

//  Copyright (c) 2015年 super man. All rights reserved.

//

 

#import "RootViewController.h"

 

@interface RootViewController ()<UIScrollViewDelegate>

{

    UIScrollView *_scrollView;

    UIImageView *_image;

    

}

@end

 

@implementation RootViewController

 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    _scrollView=[[UIScrollView alloc]initWithFrame:self.view.bounds];

    [self.view addSubview:_scrollView];

    

    _image=[[UIImageView alloc]init];

    _image.image=[UIImage imageNamed:@"meinv"];

    CGFloat imageW=_image.image.size.width;

    CGFloat imageH=_image.image.size.height;

    _image.frame=CGRectMake(0.0, 0.0, imageW, imageH);

    

    [_scrollView addSubview:_image];

    //滚动视图的尺寸

    _scrollView.contentSize=_image.image.size;

    //隐藏水平、垂直滚动条

    _scrollView.showsHorizontalScrollIndicator=NO;

    _scrollView.showsHorizontalScrollIndicator=NO;

    //增加额外的滚动区域(逆时针,上、左、下、右)

    _scrollView.contentInset=UIEdgeInsetsMake(20, 20, 20, 20);

    //最大比例

    _scrollView.maximumZoomScale=2.0;

    //最小比例

    _scrollView.minimumZoomScale=0.5;

    //实现委托

    _scrollView.delegate=self;

    

    

    // Do any additional setup after loading the view.

}

#define UIScrollViewDelegate

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

    

    return _image;

}

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

/*

 #pragma mark - Navigation

 

 // In a storyboard-based application, you will often want to do a little preparation before navigation

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

 {

 // Get the new view controller using [segue destinationViewController].

 // Pass the selected object to the new view controller.

 }

 */

 

@end

 

UIScrollerView 的简单使用

标签:

原文地址:http://www.cnblogs.com/zhuzhushen/p/4286859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!