博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIScrollView、UIPageControl的练习
阅读量:7047 次
发布时间:2019-06-28

本文共 2214 字,大约阅读时间需要 7 分钟。

  hot3.png

代码功能,实现图的自动播放~

 

.h

#import <UIKit/UIKit.h>

 ViewController : UIViewController<UIScrollViewDelegate>

(nonatomic,strong)UIImageView *imageView;

(nonatomic,strong)UIScrollView *scrollView;

(nonatomic,strong)UIPageControl *PageControl;

(nonatomic,strong)NSTimer *timer;

@end

.m

#import "ViewController.h"

@interfaceViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    _timer=[NSTimer  scheduledTimerWithTimeInterval:2.0ftarget:selfselector:@selector(autoBegin) userInfo:nilrepeats:nil];

    _scrollView=[[UIScrollViewalloc]initWithFrame:CGRectMake(32.5100300,300)];

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

        _imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(i*3000300,300)];

        NSString *str=[NSStringstringWithFormat:@"%i.jpg",i+1];

        _imageView.image=[UIImageimageNamed:str];

       [_scrollViewaddSubview:_imageView];

    }

    

    _scrollView.contentSize=CGSizeMake_scrollView.frame.size.width * 8 , 0);

    _PageControl=[[UIPageControlalloc]initWithFrame:CGRectMake(32.5330300100)];

    _PageControl.currentPage=0;

    _PageControl.numberOfPages=8;

    _PageControl.currentPageIndicatorTintColor=[UIColorblueColor];

    _PageControl.pageIndicatorTintColor=[UIColorblackColor];

    _scrollView.delegate=self;

    [self.viewaddSubview:_PageControl];

    [self.viewaddSubview:_scrollView];

    [self.viewbringSubviewToFront:_PageControl];

    _scrollView.pagingEnabled = YES;

    

    

}

- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

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

{

       return_imageView;

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    CGFloat FloatX= _scrollView.contentOffset.x;

    _PageControl.currentPage = FloatX / _scrollView.frame.size.width;

}

-(void)autoBegin

{

    [UIViewanimateWithDuration:1.0fanimations:^{

        CGFloat offsetX =  _scrollView.contentOffset.x;

        offsetX += 300;

        if( offsetX == _scrollView.contentSize.width ){

            offsetX = 0;

        }

               _scrollView.contentOffset = CGPointMake( offsetX, 0);

    }];

    _timer=[NSTimer  scheduledTimerWithTimeInterval:2.0ftarget:selfselector:@selector(autoBegin) userInfo:nilrepeats:nil];

}

转载于:https://my.oschina.net/jlong/blog/472713

你可能感兴趣的文章
编写获取真实IP的工具类
查看>>
Linux信号(signal) 机制分析
查看>>
cisco asa5505 transparent v8.4&v7.2
查看>>
NAT技术基础解析
查看>>
求完数
查看>>
快速高效地开发和调试基于gradle管理的web应用
查看>>
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
查看>>
SolrCloud+tomcat7+zookeeper集群配置
查看>>
Dubbo之服务暴露
查看>>
一点感叹
查看>>
使用Feign实现Form表单提交
查看>>
linux 压缩及归档
查看>>
Linux下的DNS
查看>>
floor和ceil函数的返回自是double型的
查看>>
14.3继承
查看>>
死锁预防和死锁防止
查看>>
leetcode--合并两个有序的链表
查看>>
企业运维—玩转 windows server 2016 DNS服务
查看>>
Scala flatMap的变体
查看>>
rpm,yum程序包管理器
查看>>