- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClick)];
self.navigationItem.leftBarButtonItem = leftButton;
[leftButton release];
isFreshInitSelf = TRUE;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
scrollPagesCount = 4;
}
else
{
scrollPagesCount = 7;
}
}
return self;
}
- (void)viewDidLoad
{[super viewDidLoad];
scrollView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor clearColor];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
leftTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, LEFTMENU_VIEW_WIDTH, CGRectGetHeight(self.view.bounds))];
leftTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
leftTableView.backgroundColor = [UIColor clearColor];
leftTableView.rowHeight = 120;
NSString *imageName = @"bg_left_menunav.png";
if (CGRectGetWidth(self.view.bounds) > 768) {
imageName = @"bg_left_menunav_landscape.png";
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, LEFTMENU_VIEW_WIDTH, CGRectGetHeight(self.view.bounds))];
imageView.image = [UIImage imageNamed:imageName];
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[leftTableView addSubview:imageView];
[imageView release];
[self.view addSubview:leftTableView];
}
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (isFreshInitSelf == TRUE) {
CGRect rect;
if (scrollPagesCount == 1) {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
rect = self.view.frame;
rect.origin.x += 200;
rect.size.width -= 200;
scrollView.frame=rect;
}
}
[self setupScheduleScrollPage]; //分屏显示,不知是否有问题,请大侠指教~~
isFreshInitSelf = FALSE;
}else {
[self setScheduleScrollViewSubViewsLayoutForRotation];
}
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewDidUnload
{
[scrollView release];
[leftTableView release];
[rightTableView release];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return [[MiraclePushClientAppDelegate getApp] allowAutoScreen];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[self setScheduleScrollViewSubViewsLayoutForRotation];
}
#pragma UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)_scrollView
{
if (pageControlIsChangingPage) {
return;
}
/*
* We switch page at 50% across
*/
CGFloat pageWidth = _scrollView.frame.size.width;
int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
//由于最左侧去掉了一个200宽度的一个空间,scrollview只占用的568的宽度,可是此处的_scrollView.contentOffset.x 一直是768(实际是否为568)为什么
??
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)_scrollView
{
pageControlIsChangingPage = NO;
}
- (void) backButtonClick
{
[MiraclePushClientAppDelegate getApp].rootController.scheduleViewScroller = nil;
[[self navigationController] popViewControllerAnimated:YES];
//add 09-13
[[MiraclePushClientAppDelegate getApp].rootController.mainViewScrollerController sendReqToGetMenuInfoData];
}
//分屏显示以及设置scrollView有问题????
{
if (scrollView.delegate == nil) {
scrollView.delegate = self;
[scrollView setBackgroundColor:[UIColor clearColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CGFloat tableViewWidth = self.view.bounds.size.width - 200;
CGFloat tableViewHeight = self.view.bounds.size.height;
NSInteger cx = 200;
for (NSInteger i=0; i< scrollPagesCount ; i++) {
CGRect frame = CGRectMake(cx, 0, tableViewWidth, tableViewHeight);
UIView *tv = [[UIView alloc] initWithFrame:frame];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
NSString *str = [[NSString alloc] initWithFormat:@"View%d", i];
label.text = str;
[tv addSubview:label];
[label release];
[scrollView addSubview:tv];
[tv release];
tv = nil;
cx += frame.size.width;
}
scrollView.frame = self.view.frame;
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
}
else
{
CGFloat tableViewWidth = self.view.bounds.size.width;
CGFloat tableViewHeight = self.view.bounds.size.height;
NSInteger cx = 0;
for (NSInteger i=0; i<scrollPagesCount ; i++) {
CGRect rect = CGRectMake(cx, 0, tableViewWidth, tableViewHeight);
UIView *tv = [[UIView alloc] initWithFrame:rect];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 100)];
NSString *str = [[NSString alloc] initWithFormat:@"View%d", i];
label.text = str;
[tv addSubview:label];
[label release];
[scrollView addSubview:tv];
[tv release];
tv = nil;
cx += rect.size.width;
}
scrollView.frame = self.view.frame;
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
}
}
- (void)setScheduleScrollViewSubViewsLayoutForRotation {
for(UIView *subview in [scrollView subviews]) {
[subview removeFromSuperview];
}
[self setupScheduleScrollPage];
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * currentPageNum;
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];
}