|
| 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