自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開(kāi)發(fā)應(yīng)用中UIScrollView代碼實(shí)現(xiàn)循環(huán)滾動(dòng)

移動(dòng)開(kāi)發(fā) iOS
iPhone開(kāi)發(fā)應(yīng)用中循環(huán)滾動(dòng)一個(gè)UIScrollView代碼實(shí)現(xiàn)是本文要介紹的內(nèi)容,主要是介紹UIScrollView來(lái)實(shí)現(xiàn)循環(huán)滾動(dòng)的案例,來(lái)看詳細(xì)內(nèi)容。

iPhone開(kāi)發(fā)應(yīng)用中循環(huán)滾動(dòng)一個(gè)UIScrollView代碼實(shí)現(xiàn)是本文要介紹的內(nèi)容,主要是介紹UIScrollView來(lái)實(shí)現(xiàn)循環(huán)滾動(dòng)的案例,來(lái)看詳細(xì)內(nèi)容。

  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,也就是要開(kāi)始循環(huán)的第一個(gè)           
  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 

小結(jié):iPhone開(kāi)發(fā)應(yīng)用中循環(huán)滾動(dòng)一個(gè)UIScrollView代碼實(shí)現(xiàn)的內(nèi)容介紹完了,希望通過(guò)本文的學(xué)習(xí)能對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2013-03-29 11:06:24

iOS開(kāi)發(fā)滾動(dòng)視圖UIScrol

2011-08-03 17:27:40

iPhone UIScrollVi

2011-07-25 14:44:41

iPhone iPhone開(kāi)發(fā) 截屏

2011-08-15 15:44:46

iPhone開(kāi)發(fā)PDF

2011-08-18 16:24:44

iPhone開(kāi)發(fā)圖片

2011-08-16 15:48:37

iPhone開(kāi)發(fā)抓圖程序

2011-08-19 10:05:30

iPhone開(kāi)發(fā)

2011-08-18 16:42:07

iPhone應(yīng)用APNS推送

2011-08-11 17:32:51

iPhone視圖

2011-08-10 14:40:23

iPhone動(dòng)畫(huà)

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-19 14:34:03

iPhone開(kāi)發(fā)

2011-07-27 11:19:33

iPhone UITableVie

2011-08-16 14:54:12

iphone開(kāi)發(fā)APP

2011-08-22 14:12:48

iPhone開(kāi)發(fā)NSTableView

2011-08-15 11:37:20

iPhone開(kāi)發(fā)Mask

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-12 14:33:06

iPhone緩存文件

2011-08-02 14:23:09

iPhone UIScrollVi 圖片

2012-04-26 13:26:58

iPhone應(yīng)用技巧
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)