iOS笔记之ScrollView
ScrollView三个基本的要理解的属性;
contentSize
The size of the content view.所以很好理解,contentSize也就是scrollView可滚动的区域.
contentOffset
The point at which the origin of the content view is offset from the origin of the scroll view.
这里标注的是point,是scrollview当前显示区域顶点相对于frame顶点的偏移量.
contentInset
The distance that the content view is inset from the enclosing scroll view.
这里说得是distance,四个值分别是上下左右, 默认值是 UIEdgeInsetsZero,也就是四个值都为0.是scrollview的contentview的顶点相对于scrollview的位置.
_|←_cW_→_|_↓_
| |
---------------
|content| ↑
↑ |content| contentInset.top
cH |content|
↓ |content| contentInset.bottom
|content| ↓
---------------
_|_______|___
↑ (cH = contentSize.height; cW = contentSize.width)
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView; //返回要缩放的图片(必须在代理类里实现)
图片缩放保持居中,实现代码:
(在viewWillLayoutSubviews也要调用)
func recenterImage() {
let scrollViewSize = scrollView.bounds.size
let imageSize = imageView.frame.size
let horizontalSpace = imageSize.width < scrollViewSize.width ? (scrollViewSize.width - imageSize.width) / :
let verticalSpace = imageSize.height < scrollViewSize.height ? (scrollViewSize.height - imageSize.height) / :
scrollView.contentInset = UIEdgeInsets(top: verticalSpace,
left: horizontalSpace,
bottom: verticalSpace,
right: horizontalSpace)
}
ScrollView中键盘的高度适应,实现代码
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
func keyboardWillShow(notification:NSNotification) {
adjustInsetForKeyboard(true, notification: notification)
}
func keyboardWillHide(notification:NSNotification) {
adjustInsetForKeyboard(false, notification: notification)
}
func adjustInsetForKeyboard(show:Bool, notification:NSNotification) {
let userInfo = notification.userInfo ?? [:]
let keyboardFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue()
let adjustHeight = (keyboardFrame.height + ) * (show ? : -)
scrollView1.contentInset.bottom += adjustHeight
scrollView1.scrollIndicatorInsets.bottom += adjustHeight
}
iOS笔记之ScrollView的更多相关文章
- IOS第六天(3:scrollView 图片轮播器)
IOS第六天(3:scrollView 图片轮播器) #import "HMViewController.h" #define kImageCount 5 @interface H ...
- Android仿IOS回弹效果 ScrollView回弹 总结
Android仿IOS回弹效果 ScrollView回弹 总结 应项目中的需求 须要仿IOS 下拉回弹的效果 , 我在网上搜了非常多 大多数都是拿scrollview 改吧改吧 试了一些 发现总 ...
- 荼菜的iOS笔记--UIView的几个Block动画
前言:我的第一篇文章荼菜的iOS笔记–Core Animation 核心动画算是比较详细讲了核心动画的用法,但是如你上篇看到的,有时我们只是想实现一些很小的动画,这时再用coreAnimation就会 ...
- 【IOS笔记】Gesture Recognizers
Gesture Recognizers Gesture recognizers convert low-level event handling code into higher-level acti ...
- IOS笔记 1
< ![CDATA[ 笔记 UIWindows 与UIView的关系iOS的坐标系统视图层次结构视图坐标(Frame和Bounds区别)UIView的常用属性和方法坐标系统的变换UIView内容 ...
- 【转】iOS笔记-自定义控件(OC)
原文网址:http://www.jianshu.com/p/f23862eb7b8a 导读: iOS开发中,很多时候系统提供的控件并不能很好的满足我们的需求,因此,自定义控件便成为搭建UI界面中必不可 ...
- iOS笔记———数据存储
应用沙盒:应用文件系统的根目录,每个应用都有独自的沙盒相互:在xcode中可以用NSHomeDirectory()函数,打印当前应用的沙盒根路径. 应用程序包:包含了所有资源文件和执行文件; * Do ...
- Xamarin开发IOS笔记:切换输入法时输入框被遮住
在进行IOS开发的过程中,出现类似微信朋友圈的交互界面,当用户遇到感兴趣的内容可以进行评论.为了方便评论输入,当出现评论输入框的时候自动将评论输入框移动至键盘的上方,这样方便边输入边查看. 当用户隐藏 ...
- IOS笔记之UIKit_UIScrollView
//通过系统的一个接口 拿到是不是第一次启动这个程序 如果是就调用导航页 如果不是 直接进入下一个视图 NSUserDefaults *userDefaults = [NSUserDefaults s ...
随机推荐
- T-SQL练习题
转自:http://www.cnblogs.com/jenrrychen/p/5348546.html 1 - 3 题: 数据表结构: OrderID ProductID OrderDate Sal ...
- Portugal 2 1 minute has Pipansihuan Germany and USA tacit or kick the ball
C Luo assists last moment so that Portugal "back to life", but with just two games to allo ...
- Kconfig文件说明2
Konfig详解: 当执行#make menuconfig时会出现内核的配置界面,所有配置工具都是通过读取"arch/$(ARCH)Kconfig"文件来生成配置界面,这个文件就是 ...
- oracle 死锁查询及处理
SELECT bs.username "Blocking User", bs.username "DB User", ws.userna ...
- C++中的RAII介绍 资源管理
摘要 RAII技术被认为是C++中管理资源的最佳方法,进一步引申,使用RAII技术也可以实现安全.简洁的状态管理,编写出优雅的异常安全的代码. 资源管理 RAII是C++的发明者Bjarne Stro ...
- uva1146 2-SAT问题
题意大白书 二分答案,然后对于每个可能的答案,跑一遍2-SAT就好了. #include <iostream> #include <string.h> #include < ...
- python uwsgi报错epoll_ctl(): Bad file descriptor
今天安装了uwsgi+supervisord+nginx,一直访问不了 直接启动uwsgi使用nginx访问,查看有大量报错:epoll_ctl(): Bad file descriptor [cor ...
- Python 如何判断一个函数是generator函数?
如何判断一个函数是否是一个特殊的 generator 函数?可以利用 isgeneratorfunction 判断: >>>from inspect import isgenerat ...
- Java的Servlet、Filter、Interceptor、Listener
写在前面: 使用Spring-Boot时,嵌入式Servlet容器可以通过扫描注解(@ServletComponentScan)的方式注册Servlet.Filter和Servlet规范的所有监听器( ...
- 20145329 《网络对抗技术》MS08_067远程漏洞攻击
MS08_067远程漏洞攻击:shell 实现攻击的前提是:攻击机和靶机在同一个网段下,首先将kali的ip改为与winxp的ip一样,二者能ping通 两台虚拟机: kali ip:192.168. ...