zoukankan      html  css  js  c++  java
  • UIScrollView

    对于Scroll views一个最基础的问题就是content size。Scroll view将严格按照这个size来展示其内容。

    展示一个size大于screen的图片:

    头文件:

    #import <UIKit/UIKit.h>

     

    @interface ViewController : UIViewController<UIScrollViewDelegate>

     

    @property (strong,nonatomic) UIImageView *imageView;

    @property (nonatomic,strong) UIScrollView *myScrollView;

     

    @end

     

     

    实现

    #import "ViewController.h"

     

    @interfaceViewController ()

     

    @end

     

    @implementation ViewController

     

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    /* Gets called when user scrolls or drags */

    self.myScrollView.alpha = 0.50f;

    }

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    /* Gets called only after scrolling */

        self.myScrollView.alpha = 1.0f;

    }

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

        /* Make sure the alpha is reset even if the user is dragging */

        self.myScrollView.alpha = 1.0f;

    }

     

    - (void)viewDidLoad

    {

        [superviewDidLoad];

        UIImage *image = [UIImage imageNamed:@"viewImage"];

        self.imageView = [[UIImageView alloc] initWithImage:image];

        self.myScrollView = [[UIScrollViewalloc] initWithFrame:self.view.bounds];

        [self.myScrollViewaddSubview:self.imageView];

        self.myScrollView.contentSize = self.imageView.bounds.size;

        self.myScrollView.delegate = self;

        self.myScrollView.indicatorStyle =UIScrollViewIndicatorStyleDefault; //scroll的样式

        [self.viewaddSubview:self.myScrollView];

    }

     

    - (void)didReceiveMemoryWarning

    {

        [superdidReceiveMemoryWarning];

    }

     

    @end

     

     

    scroll views最大的特点就是可以标记页码:

    - (UIImageView *) newImageViewWithImage:(UIImage *)paramImage

                                      frame: (CGRect)paramRect {

        UIImageView *resule = [[UIImageView alloc]initWithImage:paramImage];

        resule.frame = paramRect;

        

        return resule;

    }

     

    - (void)viewDidLoad

    {

        [superviewDidLoad];

        self.view.backgroundColor = [UIColorwhiteColor];

        UIImage *iPhone = [UIImage imageNamed:@"iPhone.png"];

        UIImage *iPad = [UIImage imageNamed:@"iPad.png"];

        UIImage *macBookAir = [UIImage imageNamed:@"MacBookAir.png"];

        CGRect scrollViewRect = self.view.bounds;

        self.myScrollView = [[UIScrollView alloc] initWithFrame:scrollViewRect];

        self.myScrollView.pagingEnabled = YES;   

        self.myScrollView.contentSize = CGSizeMake(scrollViewRect.size.width * 3.0f,scrollViewRect.size.height);

        [self.viewaddSubview:self.myScrollView];

        

        CGRect imageViewRect = self.view.bounds;

        UIImageView *iPhoneImageView = [self newImageViewWithImage:iPhone frame:imageViewRect];

        [self.myScrollView addSubview:iPhoneImageView];

        /* Go to next page by moving the x position of the next image view */

        imageViewRect.origin.x += imageViewRect.size.width;

        UIImageView *iPadImageView = [self newImageViewWithImage:iPad

                                           frame:imageViewRect];

        [self.myScrollView addSubview:iPadImageView];

        /* Go to next page by moving the x position of the next image view */

        imageViewRect.origin.x += imageViewRect.size.width;

        UIImageView *macBookAirImageView =

        [self newImageViewWithImage:macBookAir frame:imageViewRect];

        [self.myScrollView addSubview:macBookAirImageView];

    }

  • 相关阅读:
    比特币节点同步问题
    Vue用axios跨域访问数据
    vue之vue-cookies安装和使用说明
    vuejs目录结构启动项目安装nodejs命令,api配置信息思维导图版
    使用以太坊智能合约实现面向需要做凭证的企业服务帮助企业信息凭证区块链化
    将任意文件写入以太坊区块的方法,把重要事件,历史事件,人生轨迹加密记录到区块链永久封存
    Linux下几种重启Nginx的方式,找出nginx配置文件路径和测试配置文件是否正确
    php小数加减精度问题,比特币计算精度问题
    Fabric架构:抽象的逻辑架构与实际的运行时架构
    国外互联网大企业(flag)的涨薪方式
  • 原文地址:https://www.cnblogs.com/liuhong/p/3284654.html
Copyright © 2011-2022 走看看