Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created December 17, 2010 07:30
Show Gist options
  • Save marshluca/744617 to your computer and use it in GitHub Desktop.
Save marshluca/744617 to your computer and use it in GitHub Desktop.
Mscrollview
//
// MScrollView.h
// Magazine
//
// Created by wang xuefeng on 10-12-16.
// Copyright 2010 www.5yi.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "MPageView.h"
@interface MScrollView : UIScrollView {
MPageView *previousPage, *currentPage, *nextPage;
int currentIndex,coverIndex, contentsIndex;
NSMutableDictionary *magazineDict;
NSMutableArray *pageArray;
}
@property (nonatomic, retain) MPageView *previousPage, *currentPage, *nextPage;
@property (nonatomic, retain) NSMutableDictionary *magazineDict;
@property (nonatomic, retain) NSMutableArray *pageArray;
@property (nonatomic, assign) int currentIndex;
- (void)loadCurrentMagazine;
- (void)loadContentWithCurrentIndex:(int)index;
@end
//
// MScrollView.m
// Magazine
//
// Created by wang xuefeng on 10-12-16.
// Copyright 2010 www.5yi.com. All rights reserved.
//
#import "MScrollView.h"
#import "MFoundation.h"
#import "MUtility.h"
@implementation MScrollView
@synthesize previousPage,currentPage,nextPage;
@synthesize pageArray;
@synthesize magazineDict;
@synthesize currentIndex;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
self.pagingEnabled = YES;
[self loadCurrentMagazine];
return self;
}
- (void)loadCurrentMagazine
{
NSMutableDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"current_magazine"];
self.magazineDict = dict;
[dict release];
NSString *bookDirectory = [self.magazineDict objectForKey:@"book_directory"];
NSString *bookCatalog = [self.magazineDict objectForKey:@"book_catalog"];
NSString *catalogFile = [NSString stringWithFormat:@"%@/%@",bookDirectory,bookCatalog];
NSMutableArray *dataArray = [MUtility getDataArrayFromFile:catalogFile];
self.pageArray = dataArray;
[dataArray release];
[self loadContentWithCurrentIndex:[[self.magazineDict objectForKey:@"last_page"] intValue]];
}
- (void)loadContentWithCurrentIndex:(int)index
{
currentIndex = index;
currentPage = [[MPageView alloc] initWithPageIndex:index
PageDict:[pageArray objectAtIndex:index]
MagazineDict:self.magazineDict];
previousPage = [[MPageView alloc] initWithPageIndex:index-1
PageDict:[pageArray objectAtIndex:index-1]
MagazineDict:self.magazineDict];
nextPage = [[MPageView alloc] initWithPageIndex:index+1
PageDict:[pageArray objectAtIndex:index+1]
MagazineDict:self.magazineDict];
[self insertSubview:previousPage atIndex:0];
[self insertSubview:currentPage atIndex:1];
[self insertSubview:nextPage atIndex:2];
NSLog(@"%@",self.subviews);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code.
}
*/
- (void)dealloc {
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment