UIScrollView的简单使用

- UIScrollView 介绍

 

  • 问&1.UIScrollView 是干什么的? 

  • • UIScrollView 也是一种控件,继承自UIView。
    • 用来实现滚动缩放的控件

  •    什么是UIScrollView?       UIScrollView是一个能够滚动的视图控件,可以用来展示大量的内容,并且可以通过滚动查看所有的内容 

解析:

UIScrollView是直接继承于UIView, 所以UIScrollView不能直接进行addTagert做监听事件,因为只有直接继承于UIControl的才可以直接进行监听事件 ,所以这里要监听UIScrollView的事件,需要引入后面的代理模式delegate;

  

问&2: 谁在滚动,和缩放?

 -> “滚动”和”缩放”指的是针对放到 UIScrollView 控件里面的内容(可以是图片、表格、其他控件等), UIScrollView 控件本身不动

  

问&3:为什么要进行”滚动”或”缩放”?

移动设备的屏幕大小是极其有限的,因此直接展示在用户眼前的内容也相当有限

当展示的内容较多,超出一个屏幕时,用户可通过滚动手势来查看屏幕以外的内

普通的UIView不具备滚动功能,不能显示过多的内容

UIScrollView是一个能够滚动的视图控件,可以用来展示大量的内容,并且可以通过滚动查看所有的内容

 

 问&4:UIScrollView实现滚动的基本思路?

 * >1.创建一个UIScrollView控件, 设置该控件本身的大小、位置(frame)

* >2.创建要进行滚动的内容(可以是图片、表格、其他控件等)

 **—> 注意: 这个内容通常是比较多的, 屏幕放不下了所以要放到UIScrollView中可以进行滚动查看

* >3.把要滚动的内容添加到UIScrollView控件中, 让要滚动的内容作为UIScrollView控件的子控件

* >4.通过设置UIScrollView的contentSize属性, 指定要滚动的内容的实际大小 —>这里是在代码里面设置的 

** 问&5:为什么要设置UIScrollView的contentSize属性?

 

** 解析: 如果不设置contentSize, UIScrollView怎么知道实际内容有多大? UIScrollView都不知道实际内容有多大, 它怎么知道需不需要滚动? 如果实际内容比UIScrollView还小, 那么就不需要滚动。如果实际内容比UIScrollView本身的尺寸大, 那么才需要滚动。

 

** 注意: 在xcode6下不需要取消"自动布局”也能滚动 

代码演示:

 1 - UIScrollView设置滚动的基本步骤:
 2 1> 创建一个UIScrollView
 3    //直接拖拽一个UIScrollView控件到main.storyboard里面,然后设置它的frame,
 4 2> 向UIScrollView中添加内容
 5      //添加一个图片框UIImageView(也可以是其他的控件) ,把图片框尺寸设置为图片原尺寸
 6 3> 设置UIScrollView的内容的大小(contentSize)
 7   //在代码里面设置   所以这里需要拖线,将UIImageView控件和UIScrollView都拖线,
 8 
 9 -4>.代码实现 UIScrollView实现图片滚动(参考案例:大图片展示)
10 @property (weak, nonatomic) IBOutletUIScrollView *scrollView;
11 @property (weak, nonatomic) IBOutlet UIImageView *d2ImageView;
12 - (void)viewDidLoad {
13     [super viewDidLoad];
14     // 设置ScrollView的contentSize
15     // 设置scrollView的contentSize为图片框的大小
16     self.scrollView.contentSize = self.imgView.bounds.size;
17 }
18 
19 注意:在设置图片的时候,要把图片的尺寸位置为图片的原尺寸,并左上角对齐
20   图片有多大就显示多大, 这里选择是左对齐,
21   图片控件属性面板—> View —> Mode  —> Top Left
22               View —> Mode里面有很多种对齐方式,

 

转载于:https://www.cnblogs.com/anRanTimes/p/5094023.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543782.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

什么是苹果耳塞?

苹果耳塞 (Apple Earbuds) Apple Earbuds are another sound device made by Apple on 23rd October 2001. It is an in-ear sound device and it has been included in all the mobile and music devices of Apple. Apple Earbuds are quite comfortable and easy to handle w…

趣说游戏AI开发:对状态机的褒扬和批判

0x00 前言 因为临近年关工作繁忙,已经有一段时间没有更新博客了。到了元旦终于有时间来写点东西,既是积累也是分享。如题目所示,本文要来聊一聊在游戏开发中经常会涉及到的话题——游戏AI。设计游戏AI的目标之一是要找到一种便于使用并容易拓…

类中函数模板 typeof_Julia中的typeof()函数

类中函数模板 typeofJulia| typeof()函数 (Julia | typeof() function) typeof() function is a library function in Julia programming language, it is used to get the concrete type of the given value or variable. typeof()函数是Julia编程语言中的库函数,…

sencha touch调试时Please close other application using ADB: Monitor, DDMS, Eclipse

1、运行——cmd—— netstat -aon|findstr "5037" 2、打开任务管理器,查看所有进程 显示进程pid(文件-查看)--查找pid7740的结束。转载于:https://www.cnblogs.com/taoshengyujiu/p/5099588.html

定时器mia是什么意思_MIA的完整形式是什么?

定时器mia是什么意思MIA:行动失踪 (MIA: Missing In Action) MIA is an abbreviation of "Missing In Action". MIA是“缺少行动”的缩写。 It is an expression, which is commonly used in the Gmail platform. It is written to show that the origin…

window下自己主动备份数据库成dmp格式的bat写法

复制以下的命令到一个txt文本文档&#xff0c;然后改动相应的參数为自己须要的參数&#xff0c;一切完毕之后&#xff0c;将文件保存为bat格式。这样每次须要备份的时候仅仅须要双击一下这个bat文件。其它的都不用你了&#xff0c;你仅仅须要静静的等待……</pre><pre…

l和l_L&T的完整形式是什么?

l和&lL&#xff06;T&#xff1a;Larsen和Toubro (L&T: Larsen and Toubro) L&T is an abbreviation of Larsen and Toubro. It is an Indian multinational conglomerate corporation with international networks and operations. It is dynamically engaged in …

例题 3-5 生成元 digit generator

1 #include<stdio.h>2 #include<string.h>3 #define maxn 1000054 int ans[maxn]; //类似于 比较大的数组还是开导外面比较好一点,防止报错.5 int main()6 {7 int x,y,m,T,n;8 memset(ans,0,sizeof(ans)); //数组归零.9 for(m1;m<maxn;m…

CRT的完整形式是什么?

CRT&#xff1a;阴极射线管 (CRT: Cathode Ray Tube) CRT is an abbreviation of Cathode Ray Tube. Cathode Ray Tube is a vacuum tube that accommodates one or more than one electron filled guns and a phosphorescent screen, which is used in television and convent…

Python打包程序

到py2exe的官网下载程序&#xff0c;注意对应的python版本&#xff0c;比如所用的python版本为2.7&#xff0c;那么就下载适配2.7版本的py2exe软件下载完成后安装&#xff08;与普通软件安装方式相同&#xff09; 2将要转换的python脚本放到Python文件夹内 在python的目录下面&…

ruby中!!_Ruby反向! 功能

ruby中!!逆转&#xff01; Ruby中的功能 (reverse! function in Ruby) As the name suggests, reverse! function is used to reverse the elements of an array. Most of the times, we need to reverse an array but if we do it with the help of loops, the program will b…

mcal rtm_RTM的完整形式是什么?

mcal rtmRTM&#xff1a;阅读手册 (RTM: Read The Manual) RTM is an abbreviation of "Read The Manual". RTM是“阅读本手册”的缩写 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook,…

mysql悲观锁总结和实践

使用场景举例&#xff1a;以MySQL InnoDB为例商品t_goods表中有一个字段status&#xff0c;status为1代表商品未被下单&#xff0c;status为2代表商品已经被下单&#xff0c;那么我们对某个商品下单时必须确保该商品status为1。假设商品的id为1。 一、如果不采用锁&#xff0c;…

2G的完整形式是什么?

2G&#xff1a;第二代 (2G: Second Generation) 2G is an abbreviation of the "Second-Generation Cellular Network". 2G是“第二代蜂窝网络”的缩写 。 In 1991, 2G cellular networks were commercially introduced on the GSM standard in Finland by Radiolin…

推送证书

2019独角兽企业重金招聘Python工程师标准>>> 推送证书 1 openssl pkcs12 -in CertificateName.p12 -out CertificateName.pem -nodes 转换文件上传 2证书有效期 openssl x509 -in xxx.pem -noout -dates —反馈 notBeforeDec 12 07:42:27 2015 GMT notAfterDec 11…

ruby 覆盖率测试_Ruby方法覆盖

ruby 覆盖率测试Ruby中的方法重写 (Method overriding in Ruby) Method overriding simply means that there are two methods defined within the same scope and they both are used for performing different tasks. This feature is provided in an Object-oriented langua…

iOS 之 UITextField

UITextField 之 失去焦点 收起键盘 UITextField 之 手势收起键盘转载于:https://www.cnblogs.com/SimonGao/p/5106681.html

ruby推送示例_Ruby直到示例循环

ruby推送示例直到循环 (The until loop) The until loop is one of the great features of Ruby which makes it different from other programming languages. The support of until loop specifies how much user-friendly language Ruby is? 直到循环是Ruby的重要功能之一&…

Dubbo学习总结(4)——Dubbo基于Zookeeper实现分布式实例

入门实例解析 第一&#xff1a;provider-提供服务和相应的接口 创建DemoService接口 [java] view plaincopyprint? <span style"font-size:18px;">package com.unj.dubbotest.provider; import java.util.List; /** * 定义服务接口&#xff0c;该…

什么是5g全双工模式_5G的完整形式是什么?

什么是5g全双工模式5G&#xff1a;第五代 (5G: Fifth Generation) 5G is an abbreviation of the "Fifth Generation". 5G是“第五代”的缩写 。 It is the fifth-generation wireless technology for digital cellular networks that started broad operation in 2…