成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone開發應用中UIScrollView代碼實現循環滾動

移動開發 iOS
iPhone開發應用中循環滾動一個UIScrollView代碼實現是本文要介紹的內容,主要是介紹UIScrollView來實現循環滾動的案例,來看詳細內容。

iPhone開發應用中循環滾動一個UIScrollView代碼實現是本文要介紹的內容,主要是介紹UIScrollView來實現循環滾動的案例,來看詳細內容。

  1. //  testScrollViewViewController.m   
  2. //  testScrollView   
  3. //  Created by cash on 11-7-4.   
  4. //  Copyright 2011年 xbiii3s@gmail.com. All rights reserved.    
  5. #import "testScrollViewViewController.h"   
  6. @implementation testScrollViewViewController    
  7. @synthesize scrollView, slideImages;   
  8. #define WIDTH_OF_SCROLL_PAGE 320   
  9. #define HEIGHT_OF_SCROLL_PAGE 460   
  10. #define WIDTH_OF_IMAGE 320 #define HEIGHT_OF_IMAGE 460   
  11. #define LEFT_EDGE_OFSET 0    
  12. - (void)viewDidLoad {       
  13.     scrollView = [[UIScrollView alloc] init];   
  14.     CGRect scrollFrame;   
  15.     scrollFrame.origin.x = 0;       
  16.     scrollFrame.origin.y = 0;         
  17.     scrollFrame.size.width = WIDTH_OF_SCROLL_PAGE;       
  18.     scrollFrame.size.height = HEIGHT_OF_SCROLL_PAGE;       
  19.     scrollView = [[UIScrollView alloc] initWithFrame:scrollFrame];       
  20.     scrollView.bounces = YES;       
  21.     scrollView.pagingEnabled = YES;       
  22.     scrollView.delegate = self;       
  23.     scrollView.userInteractionEnabled = YES;       
  24.     slideImages = [[NSMutableArray alloc] init];       
  25.     [slideImages addObject:@"IMG_0116.PNG"];       
  26.     [slideImages addObject:@"IMG_0118.PNG"];       
  27.     [slideImages addObject:@"IMG_0119.PNG"];       
  28.     [slideImages addObject:@"main_bg.png"];       
  29.      //add the last image first        
  30.      UIImageView *imageView = [[UIImageView alloc]   
  31.      initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:([slideImages count]-1)]]]        
  32.      imageView.frame = CGRectMake(LEFT_EDGE_OFSET, 0, WIDTH_OF_IMAGE, HEIGHT_OF_IMAGE);       
  33.      [scrollView addSubview:imageView];       
  34.      [imageView release];      
  35.      for (int i = 0;i<[slideImages count];i++) {    
  36.             //loop this bit           
  37.             UIImageView *imageView = [[UIImageView alloc]   
  38.             initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:i]]];           
  39.             imageView.frame = CGRectMake((WIDTH_OF_IMAGE * i) + LEFT_EDGE_OFSET + 320, 0, WIDTH_OF_IMAGE, HEIGHT_OF_IMAGE);           
  40.             [scrollView addSubview:imageView];           
  41.             [imageView release];   
  42.       }       
  43.        //add the first image at the end       
  44.        imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:0]]];       
  45.        imageView.frame = CGRectMake((WIDTH_OF_IMAGE * ([slideImages count] + 1)) + LEFT_EDGE_OFSET, 0, WIDTH_OF_IMAGE, HEIGHT_OF_IMAGE);   
  46.         [scrollView addSubview:imageView];      
  47.         [imageView release];       
  48.         [scrollView setContentSize:CGSizeMake(WIDTH_OF_SCROLL_PAGE * ([slideImages count] + 2), HEIGHT_OF_IMAGE)];      
  49.          [scrollView setContentOffset:CGPointMake(0, 0)];       
  50.          [self.view addSubview:scrollView];      
  51.           [self.scrollView scrollRectToVisible:CGRectMake(WIDTH_OF_IMAGE,0,WIDTH_OF_IMAGE,HEIGHT_OF_IMAGE) animated:NO];        
  52.           [super viewDidLoad];} - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {    
  53.       int currentPage = floor((self.scrollView.contentOffset.x - self.scrollView.frame.size.width 
  54. / ([slideImages count]+2)) / self.scrollView.frame.size.width) + 1;      
  55.        if (currentPage==0) {    
  56.               //go last but 1 page           
  57.    [self.scrollView scrollRectToVisible:CGRectMake(WIDTH_OF_IMAGE * [slideImages count],0,WIDTH_OF_IMAGE,HEIGHT_OF_IMAGE) animated:NO];   
  58.  } else   
  59.  if (currentPage==([slideImages count]+1)) {   
  60.  //如果是最后+1,也就是要開始循環的第一個           
  61.  [self.scrollView scrollRectToVisible:CGRectMake(WIDTH_OF_IMAGE,0,WIDTH_OF_IMAGE,HEIGHT_OF_IMAGE) animated:NO];   
  62. }   
  63. }   
  64. - (void)didReceiveMemoryWarning {     
  65.   // Releases the view if it doesn't have a superview.       
  66.   [super didReceiveMemoryWarning];       
  67.   // Release any cached data, images, etc that aren't in use.   
  68.   }   
  69.  - (void)viewDidUnload {     
  70.    // Release any retained subviews of the main view.      
  71.     // e.g. self.myOutlet = nil;   
  72.  }    
  73.  - (void)dealloc {      
  74.   [scrollView release];       
  75.   [slideImages release];       
  76.   [super dealloc];  
  77. }  
  78. @end 

小結:iPhone開發應用中循環滾動一個UIScrollView代碼實現的內容介紹完了,希望通過本文的學習能對你有所幫助!

責任編輯:zhaolei 來源: 互聯網
相關推薦

2013-03-29 11:06:24

iOS開發滾動視圖UIScrol

2011-08-03 17:27:40

iPhone UIScrollVi

2011-08-15 15:44:46

iPhone開發PDF

2011-08-18 16:24:44

iPhone開發圖片

2011-07-25 14:44:41

iPhone iPhone開發 截屏

2011-08-16 15:48:37

iPhone開發抓圖程序

2011-08-19 10:05:30

iPhone開發

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-18 16:42:07

iPhone應用APNS推送

2011-08-11 17:32:51

iPhone視圖

2011-08-10 14:40:23

iPhone動畫

2011-07-27 11:19:33

iPhone UITableVie

2011-08-19 14:34:03

iPhone開發

2011-08-16 14:54:12

iphone開發APP

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-12 14:33:06

iPhone緩存文件

2011-08-22 14:12:48

iPhone開發NSTableView

2011-08-15 11:37:20

iPhone開發Mask

2011-08-19 11:10:31

iPhone應用

2011-08-19 10:13:05

iPhone開發
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲激情一区二区 | 色综合视频 | 在线看91 | 国产精品视频一区二区三区不卡 | 免费看的av | 国产精品日本一区二区在线播放 | 国产精品免费小视频 | 在线国产视频 | 久久精品视频免费观看 | 中文字幕综合 | 精品免费视频 | 欧美一区二区三区在线观看 | 日韩免费中文字幕 | 欧美精品一区二区三区蜜桃视频 | 天天综合网天天综合 | 亚洲精品电影网在线观看 | 国产高清一区二区三区 | 亚洲资源在线 | 久久精品国产一区二区电影 | 中文一区 | 2一3sex性hd | 成人黄色av网站 | 精品视频久久久久久 | 午夜精品一区二区三区在线视 | 在线观看免费毛片 | 日韩av在线一区 | 日韩欧美大片 | 日韩欧美三级电影 | 高清一区二区视频 | 国产精品国产成人国产三级 | 91精品国产91久久久久久最新 | 久久国产区 | 天堂综合网久久 | 日本粉嫩一区二区三区视频 | 国产三区四区 | 九九精品网 | 视频在线亚洲 | 国产又色又爽又黄又免费 | 日韩激情网| 久久久91| 日本天堂视频在线观看 |