淺析iPhone SDK開發基礎之OpenFlow編程

來源:互聯網
上載者:User

iPhone SDK開發基礎之OpenFlow編程是本文要將誒少的內容,當使用者介面需要按頁面顯示圖片時,使用OpenFlow庫提供的功能,將要顯示的使用者介面圖片分頁進行顯示會使編程工作變得非常快捷。該庫提供了與OS X案頭Finder程式相同的視覺效果,3-46所示就是一個使用OpenFlow庫逐頁進行圖片顯示的程式,使用者按下螢幕即可進行左右滾動顯示,雙擊圖片即可對當前顯示的圖片進行選取操作,

程式在視圖控制器的viewDidAppear()中使用refreshCoverFlow()函數初始化OpenFlow庫,通過setNumberOfImages()函數設定圖片數量,代碼如下。

 
  1. //  RootViewController.m  
  2. - (void)refreshCoverFlow{  
  3.     
  4.  CGRect bounds = [[UIScreen mainScreen] bounds];  
  5.  AFOpenFlowView *coverFlowView = (AFOpenFlowView*)[self.view viewWithTag:kTagCoverflow];  
  6.  if(coverFlowView != nil)  
  7.     [coverFlowView removeFromSuperview];   
  8.  coverFlowView = [[AFOpenFlowView alloc] initWithFrame:CGRectMake(0, -30, bounds.size.width, COVERFLOWHEIGHT)];  
  9.  coverFlowView.dataSource = self;  
  10.  coverFlowView.viewDelegate = self;  
  11.  coverFlowView.defaultImage = [self defaultImage];  
  12.  coverFlowView.tag = kTagCoverflow;  
  13.  [self.view addSubview:coverFlowView];  
  14.  
  15.     NSInteger count = [self numberOfAnimals];  
  16.  [coverFlowView setNumberOfImages:count];  
  17.  //...  
  18.  [coverFlowView release];  

並在loadView()中初始化圖片,將圖片從資源中載入並儲存在一個NSMutableArray類型的變數imageArray中,代碼如下。

 
  1. - (BOOL)doAddAnimal:(NSString *)name Image:(NSString *)imageName{  
  2.    
  3.  UIImage *image = [UIImage imageNamed: imageName];  
  4.  if(image == nil) return FALSE;  
  5.  CGSize size  = CGSizeMake(179, 208);  
  6.  [imageArray addObject:[self resizeImage:image scaledToSize:size]];  
  7.  return TRUE;   

在OpenFlow庫的requestImageForIndex delegate方法中直接通過NSMutableArray的索引作為OpenFlow庫的圖片索引,並通過該索引設定和擷取具體圖片,代碼如下。

 
  1. //  PageViewController.m  
  2. - (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex: (int)index{  
  3.      UIImage *image =  [imageArray objectAtIndex:index];  
  4.   [openFlowView setImage:image forIndex:index];  

筆者在OpenFlow庫AFOpenFlowView.m檔案的touchesEnded()函數中增加了雙擊回調介面,以便在使用者雙擊圖片時通知庫的調用者,代碼如下。

 
  1. //AFOpenFlowView.m  
  2. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {  
  3.  if(((UITouch *)[touches anyObject]).tapCount == 2){  
  4.       if ([self.viewDelegate respondsToSelector:@selector(openFlowView: coverViewDoubleClick:)])  
  5.    [self.viewDelegate openFlowView:self coverViewDoubleClick: selectedCoverView.number];  
  6.     }   
  7.     [super touchesEnded:touches withEvent:event];   

庫的調用者RootViewController類通過介面函數coverViewDoubleClick()即可處理使用者雙擊事件,代碼如下。

 
  1. - (void)openFlowView:(AFOpenFlowView *)openFlowView coverViewDoubleClick:(int)index{  
  2.   NSLog(@"coverViewDoubleClick called!");  
  3.   [self showPaintingViewController]; 

小結:淺析iPhone SDK開發基礎之OpenFlow編程的內容介紹完了,希望通過本文的學習能對你有所協助!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.