UIScrollView

//
//  RootViewController.m
//  Lesson06UIScrollView
//
//  Created by lanouhn on 16/1/7.
//  Copyright (c) 2016年 lanouhn. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController () {
    UIScrollView *scrollView;
}

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor brownColor];
    //UIScrollView, 继承于UIView, 滚动视图, 用于展示超出一个屏幕的内容.
    //frame: 可视区域的大小和位置
//    scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    scrollView.backgroundColor = [UIColor orangeColor];
    //内容页的大小, 内容页的大小必须超过可视区域的大小才可以滚动,能够装下要放的内容
    scrollView.contentSize = CGSizeMake(1000, 1000);
    //是否显示水平滚动条
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    //是否支持回弹
    scrollView.bounces = YES;
    //是否关闭滚动效果
    scrollView.scrollEnabled = YES;
    //点击状态栏滚到顶部
    scrollView.scrollsToTop = YES;
    //内容页的偏移量
    scrollView.contentOffset = CGPointMake(0, 100);
    [self.view addSubview:scrollView];
    [scrollView release];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(23, 0, 329, 924)];//图片除2, 对称放置
    imageView.image = [UIImage imageNamed:@"11.jpg"];
    //视图必须放到scrollView
    [scrollView addSubview:imageView];
    [imageView release];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(320, 600, 50, 50);
    //圆角半径
    button.layer.cornerRadius = 25;
    //描边宽度
    button.layer.borderWidth = 1;
    //描边颜色
    button.layer.borderColor = [UIColor yellowColor].CGColor;
    [button setTitle:@"顶部" forState:UIControlStateNormal];//正常状态
    //button 关联方法
    [button addTarget:self action:@selector(top) forControlEvents:UIControlEventTouchUpInside];//按下之后松手
    [self.view addSubview:button];
    [button release];


}

- (void)top {
    //1.
//    scrollView.contentOffset = CGPointZero;
    //2.有个缓慢的过程
    [scrollView setContentOffset:CGPointZero animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/



//在建一个视图
//
//  ShowViewController.m
//  Lesson06UIScrollView
//
//  Created by lanouhn on 16/1/7.
//  Copyright (c) 2016年 lanouhn. All rights reserved.
//

#import "ShowViewController.h"

@interface ShowViewController ()

@end

@implementation ShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //可视图的大小
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    //内容可以放下所
    scrollView.contentSize = CGSizeMake(375 * 4, 667);
    //是否整屏滑动
    scrollView.pagingEnabled = YES;
    [self.view addSubview:scrollView];
    [scrollView release];
    for (NSInteger i = 0; i < 4; i++) {
        //图片视图可以很好的放下图片(为了保证图片. 计算一下宽高)
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(375 * i, 0, 375, 667)];
        NSString *name = [NSString stringWithFormat:@"%ld.jpg", i + 1];
        imageView.image = [UIImage imageNamed:name];
        [scrollView addSubview:imageView];
        [imageView release];
    }


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值