Password Generator for IOS development

Source: Internet
Author: User
Tags generator reserved

Through the Imitation password generator software, practices The iOS development technology, deepens to the MVC design pattern understanding, to the previous study the dribs and drabs Review + grasps. Because the example you see is implemented using a drag-and-drop interface,

And in order to realize and better learn about iOS development, I use the pure coding method to develop, so the relative drag will be relatively slow. Although there are special layout methods in the example, but there is no processing of the screen direction changes in the event, so the horizontal screen is still problematic. In addition, for each interface has a corresponding control class, in the UIView class to implement the UI element to add the layout, in the controller to implement events, logic processing, in order to conform to the MVC design pattern.

Results show

Main technical points

The program has two main interfaces: the master page (Mainview) and the help page (Infomationview), both of which are displayed in the program's child view, mutually exclusive

When the main page is displayed, the root view of the program has an information button that navigates to the help page, while on the help page there is a navigation bar at the top of the program's root view that can be returned to the main page by the left and right buttons of the navigation bar.

When a page is switched, the animation takes a UIView animation, and its basic usage is as follows:

The code is as follows Copy Code
[UIView Beginanimations:nil Context:nil];
[UIView setanimationduration:1.0f];
[UIView Setanimationtransition:uiviewanimationtransitioncurlup ForView:self.view Cache:yes];
[Self removemainview];
[UIView commitanimations];

A uinavigationitem is divided into three parts: the left button, the title text, the right button, the main usage form such as:

The code is as follows Copy Code

uinavigationbar* bar = [[Uinavigationbar alloc] init];
[Self.view Insertsubview:bar AboveSubview:self.infomationViewController.view];

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;

Because the UIView class was initialized with only the controls added, instead of initializing the layout of the control, layout initialization is the Relayout in the class method, so I rewrite the method in the Controller class of the view corresponding class, in order to ensure that the layout is properly called before the display-(void) Viewwillappear: (BOOL) animated, which calls the layout method inside the method, as follows:

The code is as follows Copy Code
-(void) Viewwillappear: (BOOL) animated
{
if (self.autolayout)
{
[Self.view Relayout];
}
[Super viewwillappear:animated];
}

Because the experience is not enough, originally thought can accomplish things to do or a mess of problems, first last night spent one hours to write code, and then test, incredibly no picture. Adjusted, do not know what is the reason. Then today, a new project, while writing, while looking at the effect, zero-scattered, finally completed. Looks like.. Can not eat into a fat, also can not say not practice.

Main code

Program Master Controller

The code is as follows Copy Code

//
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 no 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 of the can is recreated.
}

-(void) dealloc
{
[Self removeinfomationview];
[Self removemainview];
[Super Dealloc];
}

@end

Help Page view class

The code is as follows Copy Code

//
infomationview.m
Passwordgenerator
//
Created by Arbboter on 14/12/23.
Copyright (c) 2014 Arbboter. All rights reserved.
//

#import "InfomationView.h"

@interface Infomationview ()

@property (nonatomic, retain) uilabel* Logolabel;
@property (nonatomic, retain) uiimageview* Bkimageview;

@end

@implementation Infomationview

-(ID) init
{
self = [super init];
if (self = = nil)
{
return self;
}

uilabel* label = nil;
label = [[Uilabel alloc] init];
Label.text = @ "Copyright (c) 2014 arbboter.";
Label.textalignment = Nstextalignmentcenter;
Self.logolabel = label;
[Self Addsubview:label];
[Label release];

uiimageview* ImageView = [[Uiimageview alloc] init];
Imageview.image = [UIImage imagenamed:@ "bk.jpg"];
Imageview.contentmode = Uiviewcontentmodescaleaspectfit;
Self.bkimageview = ImageView;
[Self Insertsubview:imageview BelowSubview:self.logoLabel];
[ImageView release];

return self;
}

-(void) relayout
{
Cgpoint origin = Self.frame.origin;
Cgsize size = self.frame.size;

CGFloat ymargin = 10;
CGFloat xmargin = 10;
CGFloat w = size.width-2*xmargin;
CGFloat h = 40;
CGFloat x = origin.x + xmargin;
CGFloat y = origin.y + size.height-2*ymargin-h;

_bkimageview.frame = Self.frame;
_logolabel.frame = CGRectMake (x, Y, W, h);

}

-(void) dealloc
{
[_bkimageview release];
[_logolabel release];
[Super Dealloc];
}
@end

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.