QQ登陆页面实现 分类: ios开发 2014-12-12 21:06 150人阅读 评论(0) 收藏

iOS_28仿QQ空间登录与退出
2014-09-02     我来说两句    来源:pre_eminent的JAVA学习园地  
收藏  我要投稿

最终效果图如下:

\


注意事项:<喎�"http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPjwvcD4KPHA+PHN0cm9uZz7K5Mjrv/K1xHJldHVybiBLZXk8L3N0cm9uZz48L3A+CjxwPjxzdHJvbmc+TWFpbi5zdG9yeWJvYXJk1tDOqiBMb2dpbkNvbnRyb2xsZXIgyejWw9K7uPZzdG9yeWJvYXJkSUQsPC9zdHJvbmc+PC9wPgo8cD48c3Ryb25nPtLUseO/ydLU1Nq0+sLr1tDNqLn9U3Rvcnlib2FyZLbUz/PKtcD9LLS0vahNYWluLnN0b3J5Ym9hcmTA78PmtcS/2NbGxvc8L3N0cm9uZz48L3A+CjxwPjxzdHJvbmc+PGJyPgo8L3N0cm9uZz48L3A+CjxwPjxzdHJvbmc+PGJyPgo8L3N0cm9uZz48L3A+CjxwPjxpbWcgc3JjPQ=="http://www.2cto.com/uploadfile/Collfiles/20140902/20140902085743107.png" alt="\">



仿QQ窗口抖动

\



dispach_after模拟延时

\


输入框的return Key的不同处理方式


\


Login控制器代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
//  LoginController.m
//  28_QQ空间
//
//  Created by beyond on 14-9-1.
//  Copyright (c) 2014年 com.beyond. All rights reserved.
//  Main.storyboard中初始化时的控制器,登录控制器 验证成功后,跳转至主控制器
 
#import "LoginController.h"
// 验证成功后,跳转至主控制器
#import "BeyondViewController.h"
 
@interface LoginController () <uitextfielddelegate>
#pragma mark - 拖线 属性
// 登录框整体
@property (weak, nonatomic) IBOutlet UIView *loginContentView;
// 帐号
@property (weak, nonatomic) IBOutlet UITextField *usernameField;
// 密码
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
// 登录按钮
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
// 记住密码btn
@property (weak, nonatomic) IBOutlet UIButton *rememberPwdBtn;
// 自动登录btn
@property (weak, nonatomic) IBOutlet UIButton *autoLoginBtn;
// 加载中...
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
#pragma mark - 拖线 方法
// 登录按钮被点击
- (IBAction)loginBtnClicked;
// 点击了记住密码 或 自动登录
- (IBAction)checkboxBtnClicked:(UIButton *)sender;
@end
 
@implementation LoginController
 
- (void)viewDidLoad
{
    [super viewDidLoad];
    // 1.设置登陆控制器 的背景色 为全局深黑色
    self.view.backgroundColor = kGlobalBgColor;
     
    // 2.设置登录按钮不同状态下的背景
    [self.loginBtn setBtnBgImgForNormal:@"login_button_normal" highlightedName:@"login_button_pressed"];
}
// 点击屏幕空白处,退出键盘
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
#pragma mark - 拖线方法
// 点击了记住密码 或 自动登录
- (IBAction)checkboxBtnClicked:(UIButton *)sender
{
    // 设置勾选 或 取消勾选
    sender.selected = ! sender.isSelected;
    // 重要~~~
    if (sender == self.rememberPwdBtn && !sender.isSelected) {
        // 取消了“记住密码”,这时候 就可以同时取消 自动登录了,因为用户不想记住密码,自然就无法实现 自动登录功能
        self.autoLoginBtn.selected = NO;
    } else if (sender == self.autoLoginBtn && sender.isSelected) {
        // 当用户 选中了“自动登录”,那么表示他想自动登录,那么可以同时把记住密码勾选上
        self.rememberPwdBtn.selected = YES;
    }
}
// 点击登录按钮
- (IBAction)loginBtnClicked
{
    // 1.验证帐号
    NSString *account = self.usernameField.text;
    if (account.length == 0) {
        [self showError:@"请输入帐号"];
        return;
    }
     
    // 2.验证密码
    NSString *password = self.passwordField.text;
    if (password.length == 0) {
        [self showError:@"请输入密码"];
        return;
    }
     
    // 3.发送请求
    self.view.userInteractionEnabled = NO;
    [self.activityIndicator startAnimating];
     
    // 模拟延时
    CGFloat delay = 2.0;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 4.登录完毕(请求完毕)
        [self.activityIndicator stopAnimating];
        self.view.userInteractionEnabled = YES;
         
        // 5.账号密码同时为123才是正确
        if (![account isEqualToString:@"123"]) {
            [self showError:@"帐号或密码错误"];
            return;
        }
        if (![password isEqualToString:@"123"]) {
            [self showError:@"帐号或密码错误"];
            return;
        }
         
        // 6.登录成功  跳转到主页
 
        self.view.window.rootViewController = [[BeyondViewController alloc] init];
    });
}
 
 
#pragma mark - 自定义方法
// 提示错误信息
- (void)showError:(NSString *)errorMsg
{
    // 1.弹框提醒
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"登录失败" message:errorMsg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
     
    // 2.仿QQ窗口抖动
    // 核心动画之 关键帧动画
    CAKeyframeAnimation *shakeAnim = [CAKeyframeAnimation animation];
    // 哪一个成员属性 需要动画,答:x
    shakeAnim.keyPath = @"transform.translation.x";
    shakeAnim.duration = 0.15;
    CGFloat delta = 10;
    // 数组,指定每一帧时的x值
    shakeAnim.values = @[@0, @(-delta), @(delta), @0];
    shakeAnim.repeatCount = 2;
    // 让view所在的图层执行 关键帧动画
    [self.loginContentView.layer addAnimation:shakeAnim forKey:nil];
}
 
 
#pragma mark - UITextField代理方法
// 控制器 键盘上returnKey在不同输入框下的作用,如Next 或 Done
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == self.usernameField) {
        // 帐号输入框(Next)
        [self.passwordField becomeFirstResponder];
    } else {
        // 密码框(Done),调用自定义方法,执行登录
        [self loginBtnClicked];
    }
    return YES;
}
 
@end
</uitextfielddelegate>


退出,并且回到Main.storyboard里面的初始的登录控制器


原地址:http://www.2cto.com/kf/201409/330294.html

posted @ 2014-12-12 21:06  欣哥传奇  阅读(197)  评论(0编辑  收藏  举报