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

UIScrollView

时间:2016-02-16 18:23:33      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

 
//
//  ViewController.m
//  UIScrollView01
//
//  Created by cqy on 16/2/15.
//  Copyright © 2016年 程清杨. All rights reserved.
//

#import "ViewController.h"
#define WIDTH   [[UIScreen mainScreen] bounds].size.width
#define HEIGHT  [[UIScreen mainScreen]bounds].size.height
@interface ViewController ()<UIScrollViewDelegate>{
    UIScrollView *scroll;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"a"]];
    img.frame = CGRectMake(100, 0, 150, 150);
    //设置tag值,为了后?缩放的delegate(在controller?)取到img
    img.tag = 100;
   
    scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 130, WIDTH, 150)];
    scroll.backgroundColor = [UIColor greenColor];
    //属性
    //contentsize,能够滑动的决定性因素(能够决定滚动的范围)
    scroll.contentSize = CGSizeMake(2*WIDTH, 600);
    //contentOffset 偏移
   // scroll.contentOffset = CGPointMake(-50, -50);
    //返回顶部
    scroll.scrollsToTop = YES;
    //整页滑动
    scroll.pagingEnabled = YES;
    //边界反弹
    scroll.bounces = YES;
    //能否滚动
    scroll.scrollEnabled = YES;
    //水平滚动条
    scroll.showsHorizontalScrollIndicator = YES;
    //垂直滚动条
    scroll.showsVerticalScrollIndicator = YES;
    scroll.delegate = self;
    [self.view addSubview:scroll];
   
    [scroll addSubview:img];

    // Do any additional setup after loading the view, typically from a nib.
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
      NSLog(@"已经滚动...");
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    NSLog(@"将要开始拖拽..");
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
     NSLog(@"已经结束拖拽..");
}
-(void)scrollViewWillBeginDecelerating:(UIScrollView
                                       *)scrollView{
    NSLog(@"将要开始减速..");
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSLog(@"结束减速..");
}
// 缩放有关
// 缩放开始
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
   
    return [scrollView viewWithTag:100];
}
// 缩放结束
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{
    NSLog(@"结束....");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

UIScrollView

标签:

原文地址:http://www.cnblogs.com/iQingYang/p/5193208.html

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