//
// 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的更多相关文章

随机推荐

  1. Kubuntu(14.04)共享wifi(热点)

    笔记本(kubuntu14.04)通过有线上网,共享本机无线给手机.平板及其他通过wifi上网的设备. 曾经在网上找过各种方法.下载了非常多软件都不能在本机上实现wifi共享,以下这样的方法眼下相对简 ...

  2. HDU 4941 Magical Forest 【离散化】【map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...

  3. 一款基于jQuery多图切换焦点图插件

    这次要给大家分享的也是一款jQuery图片滑块插件,之前有介绍过不少实用的jQuery焦点图插件和jQuery图片滑块插件,比如jQuery左侧Tab切换的图片滑块插件.它的特点是可以同时切换多张图片 ...

  4. Golang学习 - strings 包

    ------------------------------------------------------------ strings 包与 bytes 包中的函数用法基本一样,不再赘述. 只对 R ...

  5. [golang学习] 在idea中code & debug

    [已废弃]不需要看 idea 虽然审美倒退了n年. 不过功能还是相当好用的. idea 的go插件堪称最好的go ide. 1. 语法高亮支持 2. 智能提示 3. 跳转定义(反跳转回来) 4. 集成 ...

  6. 3.4html学习笔记之表格

    <table border=""style="border-collapse:collapse"> <caption>表格</ca ...

  7. C# 之 判断或设置以管理员身份运行程序

    一.判断程序是否以管理员权限运行 using System.Security.Principal; public bool IsAdministrator() { WindowsIdentity cu ...

  8. MD5Encoder加密支持utf-8

    import java.security.MessageDigest; public class MD5Encoder { public static String encode(String str ...

  9. [JavaEE] 深入理解Struts2的ognl标签

    OGNL是Object-Graph Navigation Language的缩写,全称为对象图导航语言,是一种功能强大的表达式语言,它通过简单一致的语法,可以任意存取对象的属性或者调用对象的方法,能够 ...

  10. 基于MFC的Opengl实现动画

    对于了解MFC程序设计的来说,就太简单了.像我这种的,还是有必要记下来. OnCreate设置定时:SetTimer(1, 10, NULL);//设置#1定时器 key point void COp ...