IOS_UI_UIScrollview

#import <UIKit/UIKit.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate>


@property (strong, nonatomic) UIWindow *window;



@end

#import "AppDelegate.h"

#import "MainViewController.h"

@interface AppDelegate ()


@end


@implementation AppDelegate

- (void)dealloc

{

    [_window release];

    [super dealloc];

}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    [_window release];

    

    

    MainViewController *mainVC = [[MainViewController alloc]init];

    self.window.rootViewController = mainVC;

    [mainVC release];

    

    return YES;

}


#import <UIKit/UIKit.h>


@interface MainViewController : UIViewController


@end

#import "MainViewController.h"


@interface MainViewController ()<UIScrollViewDelegate>


@end


@implementation MainViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];

    //UIScrollView 的使用

    UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(20, 20, 335, 500)];

    scrollview.backgroundColor = [UIColor lightGrayColor];

    [self.view addSubview:scrollview];

    [scrollview release];

    

    //给scrollview指定一个滚动的范围

    scrollview.contentSize = CGSizeMake(1000, 1000);

    //加张图片

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 400, 500)];//图片大小不只局限于屏幕宽度 只要在滚动范围内即可.

    imageView.backgroundColor = [UIColor whiteColor];

    imageView.image = [UIImage imageNamed:@"IMG_8105.JPG"];

    [scrollview addSubview:imageView];

    [imageView release];

    //scrollView滚动到得位置(偏移量) 默认y轴已经有100像素的滚动 即可以从100像素开始滚动

    scrollview.contentOffset = CGPointMake(0, 100);

    

    //自动翻页属性 翻的范围与scrollView.frame 设置一样大或者比其小自动回起点 比其大则翻页

    //一个scrollView的size算一页

    scrollview.pagingEnabled = YES;

    // 返回顶部 点击状态栏返回顶部

    scrollview.scrollsToTop = YES;

    //不允许scroll滚动

//    scrollview.scrollEnabled = NO;

    //是否显示滚动条(分横向和纵向)

//    scrollview.showsVerticalScrollIndicator = NO;

    //内容到边界就不能再拉 取消边缘弹动的效果

//    scrollview.bounces = NO;

    //scrollview 协议

    //1.签协议

    //2.指定代理人

    scrollview.delegate = self;

    //UIPageControl

    //1.设置缩放的倍数

    scrollview.minimumZoomScale = 0.5;

    scrollview.maximumZoomScale = 2;

    //2.

    //页码控制器

    UIPageControl *pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(20, 20, 335, 40)];

    pageControl.backgroundColor = [UIColor blackColor];

    

    pageControl.numberOfPages = 10;

    [pageControl addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:pageControl];

    [pageControl release];

    

    

    

    

}

- (void)pageAction:(UIPageControl *)pageC

{

    NSLog(@"当前页数:%ld",pageC.currentPage);

//    NSLog(@"当前页数:%ld",pageC.currentPage+1);

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

{

    //2. 指定一个scrollView的子视图,跟着scrollView一起缩放

    //一旦进行了缩放操作,scrollView的contentSize就和这个方法指定的View的frame.size一样大,确保能使用scrollView滚动查看这个View的所有内容

    return  [scrollView.subviews firstObject];

}

#pragma mark-//3. 实现协议方法 (requare 是必须实现的)

//3. 实现协议方法 (requare 是必须实现的)在哪个期间想做什么就在对应的期间函数里做

- (void) scrollViewDidScroll:(UIScrollView *)scrollView

{

    NSLog(@"gun");

    NSLog(@"%@",NSStringFromCGPoint(scrollView.contentOffset));

}

- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView

{

    NSLog(@"将要开始拖拽");

}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate

{

    NSLog(@"已经结束拖拽");

}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

{

    NSLog(@"将要开始减速");

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

    NSLog(@"已经结束减速");

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值