UI1_UIScrollView
//
// AppDelegate.m
// UI1_UIScrollView
//
// Created by zhangxueming on 15/7/10.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *root = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:root];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor]; return YES;
}
//
// ViewController.h
// UI1_UIScrollView
//
// Created by zhangxueming on 15/7/10.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIScrollViewDelegate> @end
//
// ViewController.m
// UI1_UIScrollView
//
// Created by zhangxueming on 15/7/10.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
imageView.image = image;
//[self.view addSubview:imageView];
//创建滚动视图
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height)];
//设置内容视图的大小
//跟imageView的大小相同
scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
[scrollView addSubview:imageView];
scrollView.backgroundColor = [UIColor redColor];
//消除导航栏的影响,显示的视图不被导航栏覆盖
self.automaticallyAdjustsScrollViewInsets = NO; //隐藏滚动条
//横向的指示条
scrollView.showsHorizontalScrollIndicator = NO;
//竖向的指示条
scrollView.showsVerticalScrollIndicator = YES; //设置边界回弹
scrollView.bounces = YES;
//滚动视图的偏移, 相对于内容视图的偏移
scrollView.contentOffset = CGPointMake(0, 0);
//设置分页
//必然有一个减速的过程
scrollView.pagingEnabled = YES;
//是否滚动
scrollView.scrollEnabled = YES; //[scrollView setContentOffset:CGPointMake(-100, -100) animated:YES];
//[scrollView flashScrollIndicators]; //设置放大缩小的系数
scrollView.delegate = self;
scrollView.minimumZoomScale = 0.2;
scrollView.maximumZoomScale = 3; [self.view addSubview:scrollView];
} #pragma mark --UIScrollViewDelegate---
//视图发生滚动时调用
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//NSLog(@"----滚动----");
}
//视图发生拖拽的时候调用
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"----拉拽----");
} //拖拽结束时调用
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"decelerate = %i", decelerate);
if (decelerate) {
NSLog(@"拖拽减速");
}
}
//返回要放大子视图
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
NSLog(@"图片被放大"); return [scrollView.subviews objectAtIndex:0];
} //当有减速过程的时候才被调用
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
NSLog(@"开始减速");
}
//如果设置分页使能, 那么该方法肯定被调用
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"减速结束");
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
UI1_UIScrollView的更多相关文章
随机推荐
- [Angular2 Router] Use Params from Angular 2 Routes Inside of Components
Angular 2’s ActivatedRoute allows you to get the details of the current route into your components. ...
- webView用法小结
1.加入权限:AndroidManifest.xml中必须使用许可"android.permission.INTERNET",否则会出Web page not available错 ...
- 慎用preg_replace危险的/e修饰符(一句话后门常用)
要确保 replacement 构成一个合法的 PHP 代码字符串,否则 PHP 会在报告在包含 preg_replace() 的行中出现语法解析错误 preg_replace函数原型: mi ...
- 类的__slots__属性
为什么有"slots"属性? 默认情况下,python对象队象的每个实例(instance)都会有一个字典来存储该实例的属性,这样做的好处在于运行时期每个对象可以任意设置新的属性. ...
- C#基础--属性 字段
访问修饰符: private: 私有成员,在类的内部才可以访问 protected: 受保护的成员,该类内部和继承类的内部可以访问 public: 公共成员, 完全公开, 没有访问限制 interna ...
- WPF之复杂形状控件
有的时候想将一张图片变成一个按钮.当然这里不是单纯讲图片作为按钮的背景. 这两者是有区别的: 前者图片即按钮,比如你有一个空心的圆圈,当你点击中间空心部分的时候是没有任何反应的因为它不是属于按钮的一部 ...
- Android动画 interpolator的用法
1. <?xml version="1.0" encoding="utf-8"?> 2. <set 3. xmlns:Android=&quo ...
- Android 常用 adb 命令
查看原文:http://blog.csdn.net/u010818425/article/details/52266593 (一)基础操作 安装app adb install -r xxx.apk / ...
- IE兼容性问题列表及解决办法
目录 概述 2 第一章:HTML 3 第一节:IE7-IE8更新 31. 如果缺少结束标记的 P 元素后跟 TABLE.FORM.NOFRAMES 或 NOSCRIPT 元素,会自动添加结束标记. 3 ...
- asp.net在word页眉插入条形码
条形码控件需要引用MSBCODE9.OCX组件.该组件的默认位置是C:\Program Files\Microsoft Office\Office12\2052\MSBCODE9.OCX using ...