IPhone SDKDevelopment BasicsOpenFlowProgramming is a small part of this article. When the user interface needs to display images by PAGE, useOpenFlowFunction provided by the Library, the user interface image to be displayed is displayed on pages, making programming very quick. This Library provides the same visual effects as the OS X desktop Finder program, as shown in 3-46OpenFlowLibrary page by page for the image display program, you can press the screen to scroll around the display, double-click the image to select the currently displayed image,
The program uses the refreshCoverFlow () function in viewDidAppear () of the View Controller to initialize the OpenFlow library and uses the setNumberOfImages () function to set the number of images. The Code is as follows.
- // RootViewController.m
- - (void)refreshCoverFlow{
-
- CGRect bounds = [[UIScreen mainScreen] bounds];
- AFOpenFlowView *coverFlowView = (AFOpenFlowView*)[self.view viewWithTag:kTagCoverflow];
- if(coverFlowView != nil)
- [coverFlowView removeFromSuperview];
- coverFlowView = [[AFOpenFlowView alloc] initWithFrame:CGRectMake(0, -30, bounds.size.width, COVERFLOWHEIGHT)];
- coverFlowView.dataSource = self;
- coverFlowView.viewDelegate = self;
- coverFlowView.defaultImage = [self defaultImage];
- coverFlowView.tag = kTagCoverflow;
- [self.view addSubview:coverFlowView];
-
- NSInteger count = [self numberOfAnimals];
- [coverFlowView setNumberOfImages:count];
- //...
- [coverFlowView release];
- }
Initialize the image in loadView (), load the image from the resource, and save it in an NSMutableArray variable imageArray. The Code is as follows.
- - (BOOL)doAddAnimal:(NSString *)name Image:(NSString *)imageName{
-
- UIImage *image = [UIImage imageNamed: imageName];
- if(image == nil) return FALSE;
- CGSize size = CGSizeMake(179, 208);
- [imageArray addObject:[self resizeImage:image scaledToSize:size]];
- return TRUE;
- }
In the requestImageForIndex delegate method of the OpenFlow library, the NSMutableArray index is used directly as the image index of the OpenFlow library. The Code is as follows.
- // PageViewController.m
- - (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex: (int)index{
- UIImage *image = [imageArray objectAtIndex:index];
- [openFlowView setImage:image forIndex:index];
- }
I added the double-click callback INTERFACE IN THE touchesEnded () function of the AFOpenFlowView. m file of the OpenFlow library to notify the caller of the library when double-clicking an image. The Code is as follows.
- //AFOpenFlowView.m
- - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- if(((UITouch *)[touches anyObject]).tapCount == 2){
- if ([self.viewDelegate respondsToSelector:@selector(openFlowView: coverViewDoubleClick:)])
- [self.viewDelegate openFlowView:self coverViewDoubleClick: selectedCoverView.number];
- }
- [super touchesEnded:touches withEvent:event];
- }
The RootViewController class of the Library can process double-click events by using the interface function coverViewDoubleClick (). The Code is as follows.
- - (void)openFlowView:(AFOpenFlowView *)openFlowView coverViewDoubleClick:(int)index{
- NSLog(@"coverViewDoubleClick called!");
- [self showPaintingViewController];
Summary: AnalysisIPhone SDKDevelopment BasicsOpenFlowI hope this article will help you with programming!