Files
ZGParallelView/ZGParallelViewForTable/DemoTableViewController.m
Zhigang Fang b9ca030f77 Ver 0.1
2013-01-07 23:59:28 +08:00

88 lines
2.8 KiB
Objective-C

//
// DemoTableViewController.m
// ZGParallelViewForTable
//
// Created by Kyle Fang on 1/7/13.
// Copyright (c) 2013 kylefang. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "DemoTableViewController.h"
#import "UITableView+ZGParallelView.h"
@interface DemoTableViewController ()
@property (strong, nonatomic) IBOutlet UIView *awesomeZG;
@property (strong, nonatomic) IBOutlet UIScrollView *headerScrollView;
@property (strong, nonatomic) IBOutlet UIPageControl *headerPageControl;
@property (strong, nonatomic) IBOutlet UIView *contontView;
@property (strong, nonatomic) IBOutlet UIImageView *avatar;
@property (nonatomic) BOOL usedPageControl;
@end
@implementation DemoTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.headerScrollView.contentSize = self.contontView.frame.size;
[self.avatar.layer setCornerRadius:5.f];
[self.avatar.layer setMasksToBounds:YES];
#warning init with or without displayRadio. This is the first line of code
//[self.tableView addParallelViewWithUIView:self.awesomeZG];
[self.tableView addParallelViewWithUIView:self.awesomeZG withDisplayRadio:0.5];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat xOffSet = scrollView.contentOffset.x;
if (xOffSet != 0) {
CGFloat pageWidth = self.headerScrollView.frame.size.width;
CGFloat alphaForContentView = xOffSet/pageWidth;
if (alphaForContentView > 1.f) {
alphaForContentView = 1.f;
} else if (alphaForContentView < 0) {
alphaForContentView = 0;
}
self.headerScrollView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7*alphaForContentView];
if (!self.usedPageControl) {
int page = floor((xOffSet - pageWidth / 2) / pageWidth) + 1;
self.headerPageControl.currentPage = page;
}
}
#warning You must call this method here, inside scrollViewDidScroll: this is the second line of code
[self.tableView updateParallelView];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
if (scrollView == self.headerScrollView) {
self.usedPageControl = NO;
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
if (scrollView == self.headerScrollView) {
self.usedPageControl = NO;
}
}
- (IBAction)pageChanged:(UIPageControl *)sender {
CGFloat headerViewWidth = self.headerScrollView.frame.size.width;
CGRect frame = self.headerScrollView.frame;
frame.origin = CGPointMake(headerViewWidth*sender.currentPage, 0);
self.usedPageControl = YES;
[self.headerScrollView scrollRectToVisible:frame animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end