// // ViewController.m // PasswordGenerator // // Created by arbboter on 14/12/23. // Copyright (c) 2014ๅนด arbboter. All rights reserved. // #import "ViewController.h" #import "MainViewController.h" #import "InfomationViewController.h" @interface ViewController () @property(nonatomic, retain) UIButton* infomationButton; @property(nonatomic, retain) MainViewController* mainViewController; @property(nonatomic, retain) InfomationViewController* infomationViewController; @property (nonatomic, retain) UINavigationBar* navagationBar; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self SwitchView]; } - (void) onInfomationView { InfomationViewController* viewController = [[InfomationViewController alloc] init]; self.infomationViewController = viewController; [self.view addSubview:viewController.view]; [viewController release]; UINavigationBar* bar = [[UINavigationBar alloc] init]; [self.view insertSubview:bar aboveSubview:self.infomationViewController.view]; self.navagationBar = bar; [bar release]; UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:@"About Password Generator"]; [bar pushNavigationItem:item animated:YES]; UIBarButtonItem* leftBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(SwitchView)]; UIBarButtonItem* rightBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(SwitchView)]; item.leftBarButtonItem = leftBarButton; item.rightBarButtonItem = rightBarButton; [item release]; [leftBarButton release]; [rightBarButton release]; } - (void) removeInfomationView { [_infomationViewController.view removeFromSuperview]; [_infomationViewController release]; _infomationViewController = nil; [_navagationBar removeFromSuperview]; [_navagationBar release]; _navagationBar = nil; } - (void) SwitchView { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0f]; if ([self.infomationButton superview]) { [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; [self removeMainView]; [UIView commitAnimations]; [self onInfomationView]; } else { [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; [self removeInfomationView]; [UIView commitAnimations]; [self onMainView]; } [self reLayout]; } - (void) removeMainView { [_infomationButton removeFromSuperview]; [_infomationButton release]; _infomationButton = nil; [_mainViewController.view removeFromSuperview]; [_mainViewController release]; _mainViewController = nil; } - (void) onMainView { UIButton* button = [UIButton buttonWithType:UIButtonTypeInfoDark]; [self.view addSubview:button]; [button addTarget:self action:@selector(SwitchView) forControlEvents:UIControlEventTouchUpInside]; self.infomationButton = button; MainViewController* viewController = [[MainViewController alloc] init]; [self.view insertSubview:viewController.view belowSubview:self.infomationButton]; self.mainViewController = viewController; [viewController release]; } - (void) reLayout { CGPoint origin = self.view.frame.origin; CGSize size = self.view.frame.size; CGFloat w = 40; CGFloat h = 40; CGFloat yMargin = 10; CGFloat xMargin = 10; CGFloat x = origin.x + size.width-2*xMargin-w; CGFloat y = origin.y + size.height - 2*yMargin - h; _navagationBar.frame = CGRectMake(origin.x, origin.y+20, size.width, 40); _infomationButton.frame = CGRectMake(x, y, w, h); } -(void) viewWillAppear:(BOOL)animated { [self reLayout]; [super viewWillAppear:animated]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void) dealloc { [self removeInfomationView]; [self removeMainView]; [super dealloc]; } @end |