固定UIScrollView滑动的方向
固定UIScrollView滑动的方向

一般而言,我们通过这两个参数CGRectMake以及contentSize就可以自动的让UIScrollView只往一个方向滚动.但我遇到过非常奇葩的情况,那就是即使设置的CGRectMake以及contentSize没有一点点问题,这个UIScrollView也能够上下左右滚动-_-!!.
为了不依赖于CGRectMake以及contentSize,我们可以通过在代理方法scrollViewDidScroll:中进行限制即可.
没有限制之前的效果:

源码:
//
// RootViewController.m
// BUG
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h" @interface RootViewController ()<UIScrollViewDelegate> {
UIScrollView *_showView;
} @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; UIImageView *showImageView = \
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"长图.jpg"]]; _showView = [[UIScrollView alloc] initWithFrame:CGRectMake(, , , )];
_showView.delegate = self;
[_showView addSubview:showImageView];
_showView.contentSize = showImageView.frame.size;
[self.view addSubview:_showView];
} - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint point = scrollView.contentOffset;
// point.y = 0.f;
scrollView.contentOffset = point;
} @end
限制后效果:

//
// RootViewController.m
// BUG
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h" @interface RootViewController ()<UIScrollViewDelegate> {
UIScrollView *_showView;
} @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; UIImageView *showImageView = \
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"长图.jpg"]]; _showView = [[UIScrollView alloc] initWithFrame:CGRectMake(, , , )];
_showView.delegate = self;
[_showView addSubview:showImageView];
_showView.contentSize = showImageView.frame.size;
[self.view addSubview:_showView];
} - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint point = scrollView.contentOffset; // 限制y轴不动
point.y = .f; scrollView.contentOffset = point;
} @end
核心代码:

固定UIScrollView滑动的方向的更多相关文章
- 移动应用滑动屏幕方向判断解决方案,JS判断手势方向
问题分类 滑动屏幕打开相应功能操作. 问题描述 1.用户手动滑动屏幕,根据滑动的方向,打开相应的功能(如:向上滑摇钱树经验明细,向下滑打开任务明细,向左滑打开聚宝盆物品查看等功能),滑动事件捕获问题. ...
- UIScrollView 滑动复位
需求 在每次打开界面滑动列表都是复位状态(未滑动). 分析 在制作滑动列表时常常会结合UIPanel和UIScrollView 要让滑动列表回到未滑动时的位置,那么就需要改变Panel的Clippin ...
- 头部固定下面滑动&&获取手机屏高
height(){ //获取屏高 let phone_height = document.documentElement.clientHeight; let group = this.refs.sea ...
- UIScrollView 滑动试图
UIScrollView --->UIView //创建UIScrollView testScrollView=[[UIScrollView alloc]init]; testScrollVie ...
- iOS判断UIScrollView的滚动方向
- (void) scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat newY = scrollView.contentOffset.y; ...
- 判断tableVIew滑动的方向
首先设置一个旧的偏移量为0; self.oldContent = 0; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scr ...
- UIPanGestureRecognizer判断滑动的方向
.h文件 CGFloat const gestureMinimumTranslation = 20.0 ; typedef enum : NSInteger { kCameraMoveDirectio ...
- iOS中如何使定时器NSTimer不受UIScrollView滑动所影响
以下是使用 scheduledTimerWithTimeInterval 方法来实现定时器 - (void)addTimer { NSTimer scheduledTimerWithTimeInter ...
- 用HTML和javascript(JS)计算触屏手机手指滑动方向的演示
移动终端的流行,程序员希望通过HTML+JS完成触屏动作的识别.下面给出具体实现的例子,供大家参考. 将下面的代码复制并保存,用手机访问,现在的手机浏览器一般都支持触屏,针对本演示来讲就是支持三个js ...
随机推荐
- Jfinal本地eclipse+tomcat运行项目时候遇到错误Exception starting filter
今天想在本地eclipse上启动tomcat让项目在本地运行,但是老是报错类找不到异常. 也可能报其它错误,大概都是classNotFoundException. 九月 19, 2018 5:42:2 ...
- wordcloud+jieba
Wordcloud各参数含义 font_path : string #字体路径,需要展现什么字体就把该字体路径+后缀名写上,如:font_path = '黑体.ttf' width : int (de ...
- linux ping 命令解析
不管在windows平台,还是在linux平台,ping都是非常常用的网络命令:ping命令通过ICMP(Internet控制消息协议)工作:ping可以用来测试本机与目标主机是否联通.联通速度如何. ...
- printf()的转换说明的修饰符中的标记、数字、和.数字
先记下代码和运行结果 再解释 #include <stdio.h> #include <stdlib.h> #include <limits.h> #define ...
- elasticsearch启动错误解决
es启动默认不能使用root用户,所以需要新创建一个用户来启动. 启动时可能出现的问题: [1]: max file descriptors [4096] for elasticsearch proc ...
- Node.js进程管理之Process模块
在前面Node.js事件运行机制也有提到,Node.js应用在单个线程运行,但是现在大部分服务器都是多处理器,为了方便使用多个进程,Node.js提供了3个模块.Process模块提供了访问正在运行的 ...
- [转]Mongodb的下载和安装
本文转自:https://www.cnblogs.com/htyj/p/8260602.html 下载 下载地址:http://dl.mongodb.org/dl/win32/x86_64 说明:z ...
- sql中把时间转换成xx年xx月xx日
DECLARE @dt datetime SET @dt=GETDATE()--1.短日期格式:yyyy-m-d SELECT STUFF(STUFF(CONVERT(char(8),@dt,112) ...
- include,forward和param指令
- 骆驼拼写法(CamelCase)
在英语中,依靠单词的大小写拼写复合词的做法,叫做"骆驼拼写法"(CamelCase).比如,backColor这个复合词,color的第一个字母采用大写. 这种拼写法在正规的英语中 ...