10.1 UIScrollview概念和用法:UIScrollview基本属性用法

==========无限互联IOS视频学习笔记=====UI高级=====


1、滑动视图的基本概念和用法
·UIScrollView的基本概念和用法
·UIScrollView它是一个视图,然后它是一个可以选择滑动的视图,用与显示更多的内容
·其次,通过scrollView可以通过手势,放大或者缩小显示的内容
·UIScrollView包含两个子类,其中一个就是UITableView,因此,表视图的可以实现滑动视图的所有行为

创建一个UIScrollView实例
// 创建⼀一个UIScrollView实例
CGRect frame = CGRectMake( 0, 0, 200, 200);
UIScrollView *scrollView= [[UIScrollView alloc] initWithFrame:frame];
// 添加子视图(框架可以超过scrollview的边界)
frame= CGRectMake( 0, 0, 500, 500);
UIImageView *myImageView= [[UIImageView alloc] initWithFrame:frame]; [scrollView addSubview:myImageView];
// 设置内容尺寸
scrollView.contentSize = CGSize(500,500);


===================================



UIScrollView常用属性
contentSize
// 里面内容的大小,也就是可以滚动的大小,默认是0,没有滚动效果。
tracking
// 当 touch 后还没有拖动的时候值是YES,否则NO
zoomBouncing
// 当内容放大到最大或者最小的时候值是 YES,否则 NO 
zooming
// 当正在缩放的时候值是 YES,否则 NO 
decelerating
// 当滚动后,手指放开但是还在继续滚动中。这个时候是 YES,其它时候是 NO 
decelerationRate
// 设置手指放开后的减速率
maximumZoomScale
// ⼀一个浮点数,表示能放最大的倍数 
minimumZoomScale
// ⼀一个浮点数,表示能缩最小的倍数 
pagingEnabled
// 当值是 YES 会自动滚动到 subview 的边界。默认是NO 
scrollEnabled
// 决定是否可以滚动
showsHorizontalScrollIndicator
// 滚动时是否显示水平滚动条 
showsVerticalScrollIndicator
// 滚动时是否显示垂直滚动条 
bounces
// 默认是 yes,就是滚动超过边界会反弹有反弹回来的效果。假如是 NO,那么滚动到达边界会立刻停止。
bouncesZoom
// 和 bounces 类似,区别在于:这个效果反映在缩放上面,假如缩放超过最大缩放,那么会 反弹效果;假如是 NO,则到达最大或者最小的时候立即停止。
directionalLockEnabled
// 默认是 NO,可以在垂直和水平方向同时运动。当值是 YES 时,假如⼀一开始是垂直或者是 水平运动,那么接下来会锁定另外⼀一个方向的滚动。 假如⼀一开始是对角方向滚动,则不会禁止 某个方向
indicatorStyle
// 滚动条的样式,基本只是设置颜色。总共3个颜色:默认、黑、白 
scrollIndicatorInsets
// 设置滚动条的位置





属性测试代码:

#import "RootViewController.h"

@interface RootViewController ()
{
    UIScrollView *scrollView;
}

@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:CGRectMake(0, 20, 320, 250)];
    scrollView.backgroundColor = [UIColor redColor];
    
    // 设置内容大小
    scrollView.contentSize = CGSizeMake(320 * 5, 300 * 5);
    [self.view addSubview:scrollView];
    
    // 是否反弹
//    scrollView.bounces = NO;
    
    // 是否分页
    scrollView.pagingEnabled = YES;
    
    // 是否滚动
//    scrollView.scrollEnabled = NO;
    
    // 是否显示水平滚动条
//    scrollView.showsHorizontalScrollIndicator = NO;
    
    // 设置indicator风格
//    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    
    // 设置内容的边缘和Indicators边缘
    scrollView.contentInset = UIEdgeInsetsMake(0, 50, 0, 0);
    scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 50, 0, 0);
    
    // 提示用户,Indicators flash
    [scrollView flashScrollIndicators];
    
    // 是否同时运动,lock
    scrollView.directionalLockEnabled = YES;
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(320, 210, 320, 40)];
    label.backgroundColor = [UIColor yellowColor];
    label.text = @"学习scrolleview";
    [scrollView addSubview:label];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setFrame:CGRectMake(320/2-140/2, 350, 140, 40)];
    [button setTitle:@"Test" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)test
{
    // 移动ScrollView内容到指定位置或偏移;
    [scrollView setContentOffset:CGPointMake(320, 0) animated:YES];
    [scrollView scrollRectToVisible:CGRectMake(320, 0, 320, 300) animated:YES];
}


@end




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值