UIScrollView的简单介绍

UIScrollView有滚动和缩放两个特征,一般滚动属性要和UIPagecontrol结合使用

//

//  MainViewController.m

//  UI_lesson08

//

//  Created by xalo on 15/10/23.

//  Copyright (c) 2015 李见辉. All rights reserved.

//


#import "MainViewController.h"


#define aColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0


@interface MainViewController ()<UIScrollViewDelegate>


@end


@implementation MainViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

#pragma mark==========================UIScrollView滚动属性==============================

    

    UIScrollView *aScrollView=[[[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]]autorelease];

    aScrollView.backgroundColor=[UIColor aColor];

    [self.view addSubview:aScrollView];

    

    //滚动视图的子视图

    NSArray *titles=@[@"",@"",@"",@""];

    for (int i=0; i<4; i++) {

        UILabel *aLabel=[[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)*i, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))]autorelease];

        aLabel.text=titles[i];

        aLabel.textColor=[UIColor aColor];

        aLabel.backgroundColor=[UIColor aColor];

        aLabel.textAlignment=NSTextAlignmentCenter;

        aLabel.font=[UIFont systemFontOfSize:375 weight:600];

        aLabel.font=[UIFont fontWithName:@"Wawati SC" size:375];

        [aScrollView addSubview:aLabel];

    }

    //通过设置滑动视图的内容区域大小来让scrollView产生滑动

    //scrollView横向滑动取决于内容区域的宽度大于自身的宽度,内容区域的高度不大于自身的高度,scrollView的纵向滑动取决于内容区域的高度大于自身的高度,内容区域的宽度不大于自身的宽度

    aScrollView.contentSize=CGSizeMake(CGRectGetWidth(self.view.bounds)*4, CGRectGetHeight(self.view.bounds));//滑动范围

    

    aScrollView.contentOffset=CGPointMake(0, 0);//位置偏移量(scrollView自身的坐标轴距离左上角的相对位置,在滑动的过程中contentOffset会因为平移手势而产生改变。contentOffset的值与scrollViewboundsorgin值一样)

    

    //滑动视图的scrollToTop可以控制轻触电池条时让scrollView纵向到原始位置。也叫回到顶部,横向滑动时并没有此功能,默认此功能为YES,表示轻触回到顶部

    aScrollView.scrollsToTop=YES;

    

    //通过pagingEnabled属性可以控制视图在滑动的时候整屏滑动(一次滑动的偏移量是scrollView的宽度或者高度)

    aScrollView.pagingEnabled=YES;//默认为NO表示连续滑动

    aScrollView.bounces=YES;//控制scrollView的边缘动画是否开启(默认YES开启)

    

    //设置横向和纵向滑动指示器是否显示,默认为显示状态(在滑动的过程中才会显示)

    aScrollView.showsHorizontalScrollIndicator=NO;//水平的

    aScrollView.showsVerticalScrollIndicator=NO;//竖直的

#pragma mark==============================================================================

    aScrollView.delegate=self;//遵守代理对象

#pragma mark====================UIPageControl页面控制========================================

    UIPageControl *pageControl=[[[UIPageControl alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.bounds)-80, CGRectGetWidth(self.view.bounds), 40)]autorelease];

    //pageControl.backgroundColor=[UIColor blackColor];

    //设置pageControl的总页数,与当前的scollView当前的子视图数量相同

    pageControl.numberOfPages=4;

    //设置当前的页码,与当前的scrollview当前显示的第几个视图有关,从0开始

    pageControl.currentPage=0;

    //设置pageControl的外观颜色

    pageControl.currentPageIndicatorTintColor=[UIColor whiteColor];//当前页码指示器的前景色

    pageControl.pageIndicatorTintColor=[UIColor brownColor];//页码指示器的前景色

    [self.view addSubview:pageControl];

    

    [pageControl addTarget:self action:@selector(handlePageControlAction:) forControlEvents:UIControlEventValueChanged];//绑定响应方法

    

}


//UIScrollView滚动代理方法

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{//滚动触发

    NSLog(@"%s",__FUNCTION__);

}


-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{//开始拖拽时触发

    NSLog(@"%s",__FUNCTION__);

}


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

    NSLog(@"%s",__FUNCTION__);

}//结束拖拽时触发


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

    NSLog(@"%s",__FUNCTION__);

}//开始减速时触发



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

    NSLog(@"%s",__FUNCTION__);

    //通过偏移量除以一次偏移的大小得到页码

    NSInteger index=scrollView.contentOffset.x/CGRectGetWidth(scrollView.bounds);

    //通过快速枚举子视图数组得到对应的控件

    for (id object in self.view.subviews) {

        //判断对应的类型

        if ([object isKindOfClass:[UIPageControl class]]) {

            [(UIPageControl *)object setCurrentPage:index];

        }

    }

}//停止(减速)时触发



//联动效果

-(void)handlePageControlAction:(UIPageControl *)sender{

    //通过currenPage和一次滑动的增量得到偏移量

    CGPoint offset=CGPointZero;

    offset.x=sender.currentPage *CGRectGetWidth(self.view.bounds);

    //通过快速枚举视图的子视图数组得到对应的scrollView修改其偏移量

    for (id object in self.view.subviews) {

        if ([object isKindOfClass:[UIScrollView class]]) {

            [(UIScrollView *)object setContentOffset:offset animated:YES];

        }

    }

}











//

//  ZoomViewController.m

//  UI_lesson08

//

//  Created by xalo on 15/10/23.

//  Copyright (c) 2015 李见辉. All rights reserved.

//


#import "ZoomViewController.h"


@interface ZoomViewController ()<UIScrollViewDelegate>


@end


@implementation ZoomViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

#pragma mark==========================UIScrollView缩放属性==============================

    UIScrollView *aScrollView=[[[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]]autorelease];

    [self.view addSubview:aScrollView];

    

    UIImage *image=[UIImage imageNamed:@"/Users/xalo/Desktop/李见辉/UI/UI课程/UI_lesson08/UI_lesson08/a.jpg"];

    CGFloat width=CGRectGetWidth(self.view.bounds);

    CGFloat height=width*image.size.height/image.size.width;//根据视图的原始宽高比得到该宽度对应的高度

    UIImageView *imageView=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)]autorelease];

    imageView.center=self.view.center;

    imageView.image=image;

    [aScrollView addSubview:imageView];

    //设置scrollView的缩放的相关属性

    //设置最小缩放比例

    aScrollView.minimumZoomScale=0.5;//50%

    //设置最大缩放比例

    aScrollView.maximumZoomScale=2.0;//200%

    //imageView设置tag

    imageView.tag=123;

    //scrollView设置代理

    aScrollView.delegate=self;

    

    

}


//缩放过程中会重复响应此协议的方法

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

    NSLog(@"%@",NSStringFromCGSize(scrollView.contentSize));

    UIImageView *imageView=(UIImageView *)[scrollView viewWithTag:123];

    CGFloat content_width=scrollView.contentSize.width;

    CGFloat content_height=scrollView.contentSize.height;

    CGFloat width=CGRectGetWidth(scrollView.bounds);

    CGFloat height=CGRectGetHeight(scrollView.bounds);

    //计算缩放产生的xy轴的增量

    CGFloat delta_x=width>content_width?(width-content_width)/2:0;

    CGFloat delta_y=height>content_height?(height-content_height)/2:0;

    //重新设置视图的中心点

    imageView.center=CGPointMake(content_width/2+delta_x, content_height/2+delta_y);

}



//缩放响应

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

    return [scrollView viewWithTag:123];

}



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值