IOS_28 Imitation QQ space Login and exit

Source: Internet
Author: User

The end result is as follows:



Precautions:

Return Key of the input box

Set a storyboardid for Logincontroller in Main.storyboard,

So that the controller inside the Main.storyboard can be created through the storyboard object instance in the code.






Imitation QQ window jitter




Dispach_after Analog Delay



Different ways to handle the return key of the input box




Login Controller Code

logincontroller.m//28_qq Space////Created by Beyond on 14-9-1.//Copyright (c) 2014 Com.beyond. All rights reserved.//Main.storyboard when initializing the controller, after the login controller verification succeeds, jumps to the main controller #import "LoginController.h"//verification succeeds, jumps to the master controller # Import "BeyondViewController.h" @interface logincontroller () <UITextFieldDelegate> #pragma mark-Drag line Properties// Login box Overall @property (weak, nonatomic) Iboutlet UIView *logincontentview;//account @property (weak, nonatomic) Iboutlet Uitextfield *usernamefield;//Password @property (weak, nonatomic) iboutlet uitextfield *passwordfield;//login button @property (weak, nonatomic) Iboutlet UIButton *loginbtn;//Remember password btn@property (weak, nonatomic) iboutlet UIButton *rememberpwdbtn;//Auto Login Btn@property (Weak, nonatomic) Iboutlet UIButton *autologinbtn;//Loading ... @property (weak, nonatomic) Iboutlet Uiactivityindicatorview * Activityindicator; #pragma mark-Drag line Method//Login button is clicked-(ibaction) loginbtnclicked;//clicked remember Password or automatic login-(ibaction) Checkboxbtnclicked: (UIButton *) sender; @end @implementation logincontroller-(void) Viewdidload{[Super Viewdidload];        1. Set the background color of the login controller to global dark black self.view.backgroundColor = Kglobalbgcolor; 2. Set the login button background in different states [Self.loginbtn setbtnbgimgfornormal:@ "Login_button_normal" highlightedname:@ "Login_button_ Pressed "];} Click on the screen blank, exit the keyboard-(void) touchesended: (Nsset *) touches withevent: (uievent *) event{[Self.view Endediting:yes];} #pragma mark-Drag the Line method//Click on remember Password or automatic login-(ibaction) checkboxbtnclicked: (UIButton *) sender{//settings check or uncheck Sender.selecte D =!    sender.isselected; Important ~ ~ ~ if (sender = = self.rememberpwdbtn &&!sender.isselected) {//Cancel "Remember Password", this time you can also cancel automatic login, because the user does not    If you want to remember your password, you will not be able to implement the automatic login function self.autoLoginBtn.selected = NO;        } else if (sender = = self.autologinbtn && sender.isselected) {//When the user selects "Auto login", then he wants to log in automatically, so you can also check the remember password    self.rememberPwdBtn.selected = YES;    }}//Click the login button-(ibaction) loginbtnclicked{//1. Verify account NSString *account = Self.usernameField.text; if (Account.length = = 0) {[Self showerror:@ "Please enter account number"];    Return    }//2. Verify password NSString *password = Self.passwordField.text;        if (Password.length = = 0) {[Self showerror:@ "Please enter password"];    Return    }//3. Send Request self.view.userInteractionEnabled = NO;        [Self.activityindicator startanimating];    Analog delay CGFloat delay = 2.0; Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (Delay * nsec_per_sec)), Dispatch_get_main_queue (), ^{//        4. Login complete (request complete) [Self.activityindicator stopanimating];                self.view.userInteractionEnabled = YES; 5. The account password of 123 is the correct if (![            Account isequaltostring:@ "123"]) {[Self showerror:@ "username or password error"];        Return } if (![            Password isequaltostring:@ "123"]) {[Self showerror:@ "account number or password error"];        Return    }//6. Login successfully jump to homepage self.view.window.rootViewController = [[Beyondviewcontroller alloc] init]; });} #pragma mark-Custom method//Hint error message-(void) ShowError: (Nsstring *) errormsg{//1. Frame reminder Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Login failed" message:errormsg Deleg    Ate:nil cancelbuttontitle:@ "OK" otherbuttontitles:nil, nil];        [Alert show];    2. Imitation QQ window jitter//Core animation key frame animation cakeyframeanimation *shakeanim = [cakeyframeanimation animation];    Which member property needs animation, answer: x Shakeanim.keypath = @ "transform.translation.x";    Shakeanim.duration = 0.15;    CGFloat delta = 10;    An array that specifies the x value of each frame shakeanim.values = @[@0, @ (-delta), @ (Delta), @0];    Shakeanim.repeatcount = 2; Make keyframe animation [Self.loginContentView.layer Addanimation:shakeanim Forkey:nil] on the layer where view is located; #pragma Mark-uitextfield Proxy method//Controller keyboard Returnkey function under different input boxes, such as Next or done-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{if (TextField = = Self.usernamefield) {//Account entry box (Next) [Self.passwordfield Becomefirstresponder    ];    } else {//Password box (done), invoke custom method, execute login [self loginbtnclicked]; } return YES; @end


Exit, and return to the initial login controller inside the Main.storyboard




IOS_28 Imitation QQ space Login and exit

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.