IOS 圖片切換展示的實現,ios圖片切換展示

來源:互聯網
上載者:User

IOS 圖片切換展示的實現,ios圖片切換展示
先看看我們的效果
這種圖片切換經常出現商城或者論壇的首頁用於展示分析

這裡我用了UIScrollView和pageControll實現了一種平鋪導航,涉及到兩種操作:1 點擊pageControl換頁2 換頁轉換pageControll
實現
#import "ViewController.h"#define WEIGHT [UIScreen mainScreen].bounds.size.width#define HEIGHT [UIScreen mainScreen].bounds.size.height@interface ViewController ()<UIScrollViewDelegate>@end@implementation ViewController@synthesize topDisplayScroller;@synthesize page;- (void)viewDidLoad {    [super viewDidLoad];    [self createTopIndex];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];}#pragma mark- 建立首頁上方滑動視圖/* *  原理:建立一個分page的,scrollView , 在建立一個浮在上面的pageController————滑動展示 */-(void)createTopIndex{    topDisplayScroller.contentSize=CGSizeMake(WEIGHT*5, topDisplayScroller.frame.size.height);    topDisplayScroller.pagingEnabled=YES;//允許分頁滑動        for (int i=0; i<5; i++) {        UIImageView *ImagePage=[[UIImageView alloc]initWithFrame:CGRectMake(WEIGHT*i, 0, WEIGHT, topDisplayScroller.frame.size.height)];        ImagePage.image=[UIImage imageNamed:@"1"];        [topDisplayScroller addSubview:ImagePage];    }    /*     *  註明:添加pageControl,但是不能添加到scroller的內容視圖上,為啥呢?因為添加到上面去以後pageControl會隨之滑動     */    page=[[UIPageControl alloc]initWithFrame:CGRectMake(WEIGHT/6, 20+topDisplayScroller.frame.size.height*2/3, 50, 20)];    page.numberOfPages=5;    page.currentPageIndicatorTintColor=[UIColor orangeColor];    page.pageIndicatorTintColor=[UIColor whiteColor];    [self.page addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];    [self.view addSubview:page];}/* *  功能:滑動scroller,帶動pageControl */-(void)scrollViewDidScroll:(UIScrollView *)scrollView{    CGPoint offset=scrollView.contentOffset;    self.page.currentPage=offset.x/WEIGHT;}/* *  功能:點擊pageControll,動畫 */- (void)changePage:(id)sender{    [UIView animateWithDuration:0.3f animations:^{        NSInteger whichPage = self.page.currentPage;        topDisplayScroller.contentOffset = CGPointMake(WEIGHT* whichPage, 0.0f);    }];}@end


原始碼:https://git.oschina.net/zhengaoxing/TopIndex
本文原創,轉載請註明出處:http://blog.csdn.net/zhenggaoxing/article/details/43965373










聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.