The effect is similar to this
Recently, I have been struggling with how to build an app. I started to learn three20 some time ago. three20 is sure to simplify many problems. Many apps have used three20 with similar effects. How can I do it? I have tried it many times. There are two ideas:
1. The above ttscrollview + ttpagecontrol and the following tttableview. However, you will find that the above is always fixed. The following uitableviewRollDoes not move above.
2. Handle in tttbaleview and use tableheaderview. The Code is as follows:
#import "TSHomeViewController.h"#import "TSHomeDataSource.h"@interface TSHomeViewController ()@end@implementation TSHomeViewController- (void)dealloc { _scrollView.delegate = nil; _scrollView.dataSource = nil; TT_RELEASE_SAFELY(_scrollView); TT_RELEASE_SAFELY(_pageControl); TT_RELEASE_SAFELY(_images); [super dealloc];}- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"Home"; NSString *imgPath = [NSString stringWithFormat:@"bundle://%@.png",self.title]; self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:self.title image:TTIMAGE(imgPath) tag:0] autorelease]; NSString *text =@"http://v2.expatree.com/uploadfile/2012/0419/94bc8f2fbca0df76785a1cfbd0deb651.png,http://v2.expatree.com/images/api/lion.png"; _images =[[text componentsSeparatedByString:@","] retain]; self.tableViewStyle = UITableViewStyleGrouped; self.variableHeightRows = YES; } return self;}///////////////////////////////////////////////////////////////////////////////////////////////////- (void)createModel { self.dataSource = [[[TSHomeDataSource alloc] initWithSearchQuery:@"v2"] autorelease];}- (void)loadView { [super loadView]; self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.frame.size.width, 80.0f)]; _scrollView = [[TTScrollView alloc] initWithFrame:CGRectMake(0,0, 320, 80 )]; _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin; _scrollView.dataSource = self; _scrollView.delegate = self; _scrollView.backgroundColor = [UIColor whiteColor]; _scrollView.zoomEnabled = NO; // [_scrollView zoomToFit]; [self.tableView.tableHeaderView addSubview:_scrollView]; _pageControl = [[TTPageControl alloc] initWithFrame:CGRectMake(0,80-20, 320, 20)]; _pageControl.autoresizingMask = UIViewAutoresizingFlexibleWidth; _pageControl.backgroundColor = [UIColor clearColor]; _pageControl.currentPage = 0; _pageControl.numberOfPages = [_images count]; [_pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged]; [self.tableView.tableHeaderView addSubview:_pageControl]; }///////////////////////////////////////////////////////////////////////////////////////////////////// TTScrollViewDataSource- (NSInteger)numberOfPagesInScrollView:(TTScrollView*)scrollView { return _images.count;}- (UIView*)scrollView:(TTScrollView*)scrollView pageAtIndex:(NSInteger)pageIndex { TTView* pageView = nil; if (!pageView) { pageView = [[[TTView alloc] init] autorelease]; pageView.backgroundColor = [UIColor redColor]; pageView.userInteractionEnabled = NO; pageView.frame = CGRectMake(0,0, self.view.bounds.size.width, 80); pageView.contentMode = UIViewContentModeLeft; } TTImageView *imgView = [[TTImageView alloc]initWithFrame:CGRectZero]; [[TTURLRequestQueue mainQueue] setMaxContentLength:0]; imgView.urlPath= [_images objectAtIndex:pageIndex]; imgView.autoresizesToImage = YES; [pageView addSubview:imgView]; return [pageView autorelease];}- (CGSize)scrollView:(TTScrollView*)scrollView sizeOfPageAtIndex:(NSInteger)pageIndex { return CGSizeMake(320, 80);}#pragma mark -#pragma mark TTScrollViewDelegate- (void)scrollView:(TTScrollView*)scrollView didMoveToPageAtIndex:(NSInteger)pageIndex { _pageControl.currentPage = pageIndex;}#pragma mark -#pragma mark UIViewController overrides- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return YES;}- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];}#pragma mark -#pragma mark TTPageControl- (IBAction)changePage:(id)sender { int page = _pageControl.currentPage; [_scrollView setCenterPageIndex:page];}
Finally, indicate the source of the article. Http://www.cnblogs.com/hubj/archive/2012/05/18/2507395.html