//
// ViewController.m
// UIScrollVIew #import "ViewController.h" @interface ViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;//已经设置大小是300*200
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView1;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView2; @end @implementation ViewController - (void)viewDidLoad {//控制器类加载完毕后
[super viewDidLoad]; //1、
UIView *redView = [[UIView alloc]init];
redView.backgroundColor = [UIColor redColor];
redView.frame = CGRectMake(, , , );
[self.scrollView addSubview:redView];
self.scrollView.clipsToBounds = YES;
//设置内容尺寸,水平不能滚动,垂直滚动10,
self.scrollView.contentSize = CGSizeMake(, );
//self.scrollView.scrollEnabled = NO; 不可以滚动
//是否能够跟用户交互
self.scrollView.userInteractionEnabled = YES;
[self.scrollView.subviews.firstObject removeFromSuperview];//移除
NSLog(@"%@",self.scrollView.subviews);
/* 另外2个是滚动条,
(
"<UIView: 0x7fae0340c7d0; frame = (0 0; 50 50); layer = <CALayer: 0x600000036740>>",
"<UIImageView: 0x7fae035126b0; frame = (294.667 190; 2.33333 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x608000030f60>> - (null)",
"<UIImageView: 0x7fae03512090; frame = (290 194.667; 7 2.33333); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x608000030da0>> - (null)"
)
*/ //2、加载大图片
UIImageView* image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];//大图片
self.scrollView1.contentSize = CGSizeMake(image.frame.size.width, image.frame.size.height);
self.scrollView1.bounces = YES;//弹簧效果
self.scrollView1.alwaysBounceVertical = YES;//没有设置contentSize的时候,不能滚动,但是有时候网络加载的时候,没有数据,需要下拉刷新来加载数据,就用这个,
self.scrollView1.alwaysBounceHorizontal = YES;
self.scrollView1.showsVerticalScrollIndicator = YES;//是否显示滚动条
[self.scrollView1 addSubview:image];
self.scrollView1.contentInset = UIEdgeInsetsMake(, , , );//内边距
//self.scrollView1.contentOffset = CGPointMake(700, 700);//设置偏移
NSLog(@"%f",self.scrollView1.contentOffset.x);//获取滚动的偏移量 //3、下拉刷新,显示菊花。
UIActivityIndicatorView *iv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
iv.center = CGPointMake(, -);
[iv startAnimating];
self.scrollView2.backgroundColor = [UIColor yellowColor];
self.scrollView2.alwaysBounceVertical = YES;//没有设置contentSize不能滚动,为了下载加载并显示菊花。(不能滚动,只是有弹簧效果)
self.scrollView2.alwaysBounceHorizontal = NO;
[self.scrollView2 addSubview:iv]; //代理
UIScrollView *s = [[UIScrollView alloc]init];
s.backgroundColor = [UIColor redColor];
s.frame = CGRectMake(, , , );
[self.view addSubview:s];
UIImage * i = [UIImage imageNamed:@"car"];
UIImageView* imagev = [[UIImageView alloc]initWithImage:i];
[s addSubview:imagev];
s.contentSize = i.size;
s.delegate = self;//代理,@property(nullable,nonatomic,weak) id<UIScrollViewDelegate> delegate; 任何类型但是必须遵守UIScrollViewDelegate协议,在控制器加上遵守协议,@interface ViewController ()<UIScrollViewDelegate>,协议不写在.h文件中,因为.h文件暴露在外面给别人看的。 } //点击控制器view的空白处调用
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//self.scrollView1.contentOffset.y = 0;//不能直接修改oc对象的结构体变量的成员属性 //点击回到顶部,并且添加动画
[UIView animateWithDuration:2.0 animations:^{
CGPoint cp = self.scrollView1.contentOffset;
cp.y = ;
self.scrollView1.contentOffset = cp;
}]; //点击回到左边
[self.scrollView1 setContentOffset:CGPointMake(, self.scrollView1.contentOffset.y) animated:YES];
NSLog(@"dddd");
} -(void)scrollViewDidScroll:(UIScrollView *)scrollView //区域正在滚动时候调用
{ } -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView //开始滚动时候调用
{ } -(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset//即将停止拖拽时候调用
{ } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView//减速完毕调用
{ }
@end

ios28--UIScrollView的更多相关文章

  1. 【原】Masonry+UIScrollView的使用注意事项

    [原]Masonry+UIScrollView的使用注意事项 本文转载请注明出处 —— polobymulberry-博客园 1.问题描述 我想实现的使用在一个UIScrollView依次添加三个UI ...

  2. UIScrollView的封装

    UIScrollView的封装 效果 特点 1.用法简单,尺寸大小,随意设置位置 2.可以有多个数据源的数据,可以定制不通的界面(如同上图,一个有文字,一个没有文字) 3.能够实现点击事件 用法 1. ...

  3. UI第十七节——UIScrollView

    // 实例化一个ScrollView    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen main ...

  4. UI控件(UIScrollView)

    @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //创建一个scrollview UIScrollV ...

  5. UIScrollView的delaysContentTouches与canCencelContentTouches属性

    UIScrollView有一个BOOL类型的tracking属性,用来返回用户是否已经触及内容并打算开始滚动,我们从这个属性开始探究UIScrollView的工作原理: 当手指触摸到UIScrollV ...

  6. iOS 视图:重绘与UIScrollView(内容根据iOS编程编写)

    我们继续之前的 Hypnosister 应用,当用户开始触摸的时候,圆形的颜色会改变. 首先,在 JXHypnosisView 头文件中声明一个属性,用来表示圆形的颜色. #import " ...

  7. 学习笔记之-------UIScrollView 基本用法 代理使用

    //contentSize.contentInset和contentOffset 是 scrollView三个基本的属性. // 滚动 self.ScrollView.contentSize =sel ...

  8. iOS UIScrollView的使用

    一.为什么要用UIScrollView? 移动设备的屏幕大小是极其有限的,因此直接展示在用户眼前的内容也相当有限当展示的内容较多,超出一个屏幕时,用户可通过滚动手势来查看屏幕以外的内容普通的UIVie ...

  9. iOS之UIScrollView循环滚动

    #import "ViewController.h" #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width #d ...

  10. UIScrollView出现位移问题

    啦啦啦啦啦~~~ UINavigationController和UIScrollView一起使用时会导致UIScrollView位置偏移 情况:UINavigationController的视图上的第 ...

随机推荐

  1. jquery腾讯换肤的一些技术实现

    //检查cookie if($.cookie("skinID")){ $("#cssSkin").attr("href","/st ...

  2. 导航栏 active 跟随鼠标效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 51nod 1013 3的幂的和 - 快速幂&除法取模

    题目地址:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 Konwledge Point: 快速幂:https:/ ...

  4. buf.compare()

    buf.compare(otherBuffer) otherBuffer {Buffer} 返回:{Number} 比较两个 Buffer 实例,无论 buf 在排序上靠前.靠后甚至与 otherBu ...

  5. 初学微信小程序 TodoList

    微信小程序的学习 微信小程序的开始尝试 TodoList 微信开发者工具生成 目录如下: . |-- app.js |-- app.json |-- app.wxss |-- pages | |-- ...

  6. android 如何从activity跳转到另一个activity下指定的fragment

    思路: 跳转到目标fragment所在的activity,并传递一个flag,来确定要到哪个fragment,根据该flag判断后,跳转到指定的fragment即可. 代码: 当前界面: intent ...

  7. Python之条件 循环和其他语句 2014-4-6

    #条件 循环和其他语句 23:30pm-1:431.print和import的更多信息 使用逗号将多个表达式输出 >>> print 'age:',42 age: 42 >&g ...

  8. CodeForcesGym 100517H Hentium Scheduling

    Hentium Scheduling Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...

  9. Linux下汇编语言学习笔记22 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  10. Jam's balance set 暴力

    Jim has a balance and N weights. (1≤N≤20)(1≤N≤20) The balance can only tell whether things on differ ...