Skip to content

Commit 049f785

Browse files
author
Johannes Ekberg
committed
Added Quicksaves and added Adding Instructions to the main menu
1 parent 0587637 commit 049f785

29 files changed

+2089
-542
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// AddInstructionsViewController.h
3+
// iVN
4+
//
5+
// Created by Johannes Ekberg on 2012-02-08.
6+
// Copyright (c) 2012 MacaroniCode Software. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
@class MainMenuViewController;
11+
12+
@interface AddInstructionsViewController : UIViewController <UIScrollViewDelegate>
13+
{
14+
UIScrollView *scrollView;
15+
UIPageControl *pageControl;
16+
NSArray *pages;
17+
18+
BOOL pageControlUsed;
19+
}
20+
21+
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
22+
@property (nonatomic, retain) IBOutlet UIPageControl *pageControl;
23+
@property (nonatomic, retain) IBOutletCollection(UIView) NSArray *pages;
24+
25+
@property (nonatomic, assign) MainMenuViewController *mainMenu;
26+
27+
- (IBAction)actionClose:(id)sender;
28+
- (IBAction)actionRefresh:(id)sender;
29+
- (IBAction)actionPage:(UIPageControl *)sender;
30+
31+
@end
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// AddInstructionsViewController.m
3+
// iVN
4+
//
5+
// Created by Johannes Ekberg on 2012-02-08.
6+
// Copyright (c) 2012 MacaroniCode Software. All rights reserved.
7+
//
8+
9+
#import "AddInstructionsViewController.h"
10+
#import "MainMenuViewController.h"
11+
12+
@implementation AddInstructionsViewController
13+
@synthesize scrollView, pageControl, pages;
14+
@synthesize mainMenu;
15+
16+
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
17+
{
18+
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
19+
if (self) {
20+
// Custom initialization
21+
}
22+
return self;
23+
}
24+
25+
- (void)didReceiveMemoryWarning
26+
{
27+
// Releases the view if it doesn't have a superview.
28+
[super didReceiveMemoryWarning];
29+
30+
// Release any cached data, images, etc that aren't in use.
31+
}
32+
33+
#pragma mark - View lifecycle
34+
35+
- (void)viewDidLoad
36+
{
37+
[super viewDidLoad];
38+
// Do any additional setup after loading the view from its nib.
39+
40+
NSArray *sortedPages = [pages sortedArrayUsingComparator:^NSComparisonResult(UIView *obj1, UIView *obj2){
41+
if([obj1 tag] == [obj2 tag]) return NSOrderedSame;
42+
else return ([obj1 tag] < [obj2 tag] ? NSOrderedAscending : NSOrderedDescending);
43+
}];
44+
CGFloat xPos = 0;
45+
for(UIView *view in sortedPages)
46+
{
47+
view.frame = CGRectMake(xPos, 0, scrollView.frame.size.width, scrollView.frame.size.height);
48+
[scrollView addSubview:view];
49+
xPos += scrollView.frame.size.width;
50+
}
51+
52+
scrollView.contentSize = CGSizeMake(xPos, scrollView.frame.size.height);
53+
pageControl.numberOfPages = [sortedPages count];
54+
}
55+
56+
- (void)viewDidUnload
57+
{
58+
[super viewDidUnload];
59+
// Release any retained subviews of the main view.
60+
// e.g. self.myOutlet = nil;
61+
}
62+
63+
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
64+
{
65+
// Return YES for supported orientations
66+
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
67+
}
68+
69+
- (IBAction)actionClose:(id)sender
70+
{
71+
[self dismissModalViewControllerAnimated:YES];
72+
}
73+
74+
- (IBAction)actionRefresh:(id)sender
75+
{
76+
[mainMenu updateCollectionWithView:self.view];
77+
}
78+
79+
- (IBAction)actionPage:(UIPageControl *)sender
80+
{
81+
[scrollView scrollRectToVisible:CGRectMake(sender.currentPage*scrollView.frame.size.width, 0,
82+
scrollView.frame.size.width, scrollView.frame.size.height)
83+
animated:YES];
84+
pageControlUsed = YES;
85+
}
86+
87+
- (void)scrollViewDidScroll:(UIScrollView *)scrollView_
88+
{
89+
if(pageControlUsed) return; //Don't update if the page control triggered it, it'll cause flicker
90+
91+
pageControl.currentPage = floor((scrollView_.contentOffset.x - scrollView_.frame.size.width/2)/scrollView_.frame.size.width) + 1;
92+
}
93+
94+
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
95+
{
96+
pageControlUsed = NO;
97+
}
98+
99+
@end

0 commit comments

Comments
 (0)