UIScrollView

来源:互联网 发布:js遍历特定标签 编辑:程序博客网 时间:2024/06/09 23:40
////  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
0 0
原创粉丝点击