简单界面设置及切换

第一步:创建视图控制器并创建LoginViewController、RegistViewController、PasswordViewController三个控制器:

#import "MainViewController.h"

#import "LoginViewController.h"

#import "RegistViewController.h"

#import "PasswordViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    RegistViewController *registVC=[[RegistViewController alloc]init];

    [self.view addSubview:registVC.view];

    PasswordViewController *passwordVC=[[PasswordViewController alloc]init];

    [self.view addSubview:passwordVC.view];

    LoginViewController *logicaVC = [[LoginViewController alloc] init];

    [self.view addSubview:logicaVC.view];

}

第二步:创建LTView视图:

1、声明属性:

#import <UIKit/UIKit.h>

@interface LTView : UIView

@property(nonatomic,retain)UILabel *titleLabel;

@property(nonatomic,retain)UITextField *inputTextField;

@end

2、初始化及实现方法 :

#import "LTView.h"

 @interface LTView()<UITextFieldDelegate>

{

    CGRect _frame;

}

@end 

@implementation LTView

-(void)dealloc{

    [_titleLabel release];

    [_inputTextField release];

    [super dealloc];

-(id)initWithFrame:(CGRect)frame{

    frame=CGRectMake(0, frame.origin.y, CGRectGetWidth([[UIScreen mainScreen]bounds]), 40);

    self=[super initWithFrame:frame];

    if (self) {   

    }

    return self;

-(UILabel *)titleLabel{

    if (!_titleLabel) {

        CGFloat width=(CGRectGetWidth(self.frame)-85)/7;

        self.titleLabel=[[[UILabel alloc]initWithFrame:CGRectMake(40, 5, width*2, 30)]autorelease];

        _titleLabel.textAlignment=NSTextAlignmentLeft;

        [self addSubview:_titleLabel];

    }

    return _titleLabel;

-(UITextField *)inputTextField{

    if (!_inputTextField) {

        CGFloat width=(CGRectGetWidth(self.frame)-85)/7;

        self.inputTextField=[[[UITextField alloc]initWithFrame:CGRectMake(self.titleLabel.frame.origin.x+CGRectGetWidth(self.titleLabel.frame)+5, 5, width*5, 30)]autorelease];

        _inputTextField.borderStyle=UITextBorderStyleRoundedRect;

        _inputTextField.clearButtonMode=UITextFieldViewModeWhileEditing;

        _inputTextField.delegate=self;

        [self addSubview:_inputTextField];

    }

    return _inputTextField;

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    NSLog(@"%s",__FUNCTION__);

    [textField resignFirstResponder];

    return YES;

}

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/

@end

第三步:实现LoginViewController

#import "LoginViewController.h"

#import "LTView.h"

@interface LoginViewController ()<UITextFieldDelegate,UIAlertViewDelegate>

@end

@implementation LoginViewController 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor=[UIColor whiteColor];

    self.view.tag=0001;  

    NSArray *arrays=@[@[@"用户名",@""],@[@"密码",@""]];

    for (int i=0; i<arrays.count; i++) {

        LTView *aView=[[[LTView alloc]initWithFrame:CGRectMake(0, 100+50*i, 0, 0)]autorelease];

        aView.tag=100+i;

        aView.backgroundColor=[UIColor whiteColor];

        NSArray *array=arrays[i];

        aView.titleLabel.text=array[0];

        aView.inputTextField.placeholder=array[1];

        aView.inputTextField.clearButtonMode=UITextFieldViewModeWhileEditing;

        aView.inputTextField.delegate=self;

        [self.view addSubview:aView];

    }

    LTView *aView=(LTView *)[self.view viewWithTag:101];

    aView.inputTextField.secureTextEntry=YES;

    NSArray *title=@[@"登录",@"找回密码",@"注册"];

    for (int i=0; i<title.count; i++) {

        UIButton *abutton=[UIButton buttonWithType:UIButtonTypeSystem];

        abutton.frame=CGRectMake(40+(75+35)*i, 100+50*2, 75, 30);

        abutton.tag=1000+i;

        abutton.backgroundColor=[UIColor whiteColor];

        [abutton setTitle:title[i] forState:UIControlStateNormal];

        [abutton addTarget:self action:@selector(HandleButtonAction:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:abutton];

    }

}

-(void)HandleButtonAction:(UIButton *)sender{

    switch (sender.tag) {

        case 1000:{

            LTView *aView1=(LTView *)[self.view viewWithTag:100];

            LTView *aView2=(LTView *)[self.view viewWithTag:101];

            if (([aView1.inputTextField.text isEqualToString:@"15389022933"])&&[aView2.inputTextField.text isEqualToString:@"1234567890"]) {

                UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"欢迎回来" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];

                [alert show];

               alert.delegate=self;

                [alert release];

            }else{

                UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"用户名或者密码错误,请核对后再试" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

                [alert show];

                [alert release];

            }

            break;

        }case 1001:{

            UIView *passView=[self.view.superview viewWithTag:0003];

            [self.view.superview bringSubviewToFront:passView];

            break;

        }case 1002:{

            UIView *registView=[self.view.superview viewWithTag:0002];

            [self.view.superview bringSubviewToFront:registView];

        }

        default:

            break;

    }

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex == 0 && [alertView.message isEqualToString:@"欢迎回来"]) {

        UIView *mainView = [[UIView alloc] initWithFrame:self.view.frame];

        mainView.backgroundColor = [UIColor whiteColor];

        [self.view addSubview:mainView];

        [mainView release];

        [self.view bringSubviewToFront:mainView];

        UILabel *aLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, CGRectGetWidth(self.view.bounds), 50)];

        aLabel.text = @"欢迎回来,这里是登陆之后的主界面";

        aLabel.adjustsFontSizeToFitWidth = YES;

        aLabel.textColor = [UIColor redColor];

        aLabel.textAlignment = NSTextAlignmentCenter;

        [mainView addSubview:aLabel];

        [aLabel release];

    }

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    NSLog(@"%s",__FUNCTION__);

    [textField resignFirstResponder];

    return YES;

}

 第四步:实现RegistViewController

#import "RegistViewController.h"

#import "LTView.h"

@interface RegistViewController ()<UITextFieldDelegate,UIAlertViewDelegate>

 @end

@implementation RegistViewController

- (void)viewDidLoad {

    [super viewDidLoad];   

//    [self.view.superview viewWithTag:<#(NSInteger)#>]

    self.view.backgroundColor=[UIColor whiteColor];

    self.view.tag=0002;

    UIView *containerView=[[[UIView alloc]initWithFrame:self.view.bounds]autorelease];

    containerView.backgroundColor=[UIColor whiteColor];

    containerView.tag=1999;

    [self.view addSubview:containerView];

    NSArray *arrays=@[@[@"用户名",@"请输入用户名"],@[@"密码",@"请输入密码"],@[@"确认密码",@"再次输入密码"],@[@"手机号",@"请输入联系方式"],@[@"邮箱",@"请输入邮箱"]];

    for (int i=0; i<arrays.count; i++) {

        LTView *aView=[[[LTView alloc]initWithFrame:CGRectMake(0, 100+50*i, 0, 0)]autorelease];

        aView.inputTextField.delegate=self;

        aView.tag=200+i;

        aView.backgroundColor=[UIColor whiteColor];

        NSArray *array=arrays[i];

        aView.titleLabel.text=array[0];

        aView.inputTextField.placeholder=array[1];

        [containerView addSubview:aView];

    }

    LTView *aView1=(LTView *)[self.view viewWithTag:201];

    aView1.inputTextField.secureTextEntry=YES;

    LTView *aView2=(LTView *)[self.view viewWithTag:202];

    aView2.inputTextField.secureTextEntry=YES;

    LTView *aView3=(LTView *)[self.view viewWithTag:203];

        aView3.inputTextField.keyboardType=UIKeyboardTypeNumberPad;

    NSArray *title=@[@"注册",@"取消"];

    for (int i=0; i<title.count; i++) {

        UIButton *abutton=[UIButton buttonWithType:UIButtonTypeSystem];

        abutton.frame=CGRectMake(90+(75+45)*i, 100+50*5+50, 75, 30);

        abutton.tag=2000+i;

        abutton.backgroundColor=[UIColor whiteColor];

        [abutton setTitle:title[i] forState:UIControlStateNormal];

        [abutton addTarget:self action:@selector(HandleButtonAction:) forControlEvents:UIControlEventTouchUpInside];

        [containerView addSubview:abutton];

    }

}

-(void)HandleButtonAction:(UIButton *)sender{

    switch (sender.tag) {

        case 2000:{

            LTView *aView1=(LTView *)[self.view viewWithTag:200];

            LTView *aView2=(LTView *)[self.view viewWithTag:201];

            LTView *aView3=(LTView *)[self.view viewWithTag:202];

            if (([aView1.inputTextField.text isEqualToString:@""])||[aView2.inputTextField.text isEqualToString:@""]||[aView3.inputTextField.text isEqualToString:@""]) {

                    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"用户名或者密码错误,请核对后再试" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

                    [alert show];

                   alert.delegate=self;

                    [alert release];

                }else if(([aView1.inputTextField.text length]>6)&&[aView2.inputTextField.text isEqualToString:aView3.inputTextField.text]){

                    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"注册成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];

                    [alert show];

                    [alert release];

                }

            break;

        }case 2001:{

            UIView *loginView=[self.view.superview viewWithTag:0001];

            [self.view.superview bringSubviewToFront:loginView];

            break;

        }

        default:

            break;

    }

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if ((buttonIndex==0)&&[alertView.message isEqualToString:@"注册成功"]) {

        UIView *loginView=[self.view.superview viewWithTag:0001];

        [self.view.superview bringSubviewToFront:loginView];

    }

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    NSLog(@"%s",__FUNCTION__);

    [textField resignFirstResponder];

    return YES;

}

 第五步:实现PasswordViewController

#import "PasswordViewController.h"

//#import "LTView.h"

@interface PasswordViewController ()<UITextFieldDelegate,UIAlertViewDelegate>

@end

@implementation PasswordViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor=[UIColor whiteColor];

    self.view.tag=0003;

    NSArray *arrays=@[@"电子邮箱"];

    for (int i=0; i<arrays.count; i++) {

        UITextField *aView=[[[UITextField alloc]initWithFrame:CGRectMake(50, 100+50*i, CGRectGetWidth(self.view.bounds)-100, 30)]autorelease];

        aView.tag=300+i;

        aView.delegate=self;

        aView.backgroundColor=[UIColor whiteColor];

        aView.placeholder=arrays[i];

        aView.borderStyle=UITextBorderStyleRoundedRect;

        [self.view addSubview:aView];

    }

    NSArray *title=@[@"找回",@"取消"];

    for (int i=0; i<title.count; i++) {

        UIButton *abutton=[UIButton buttonWithType:UIButtonTypeSystem];

        abutton.frame=CGRectMake(90+(75+45)*i, 100+50*5+50, 75, 30);

        abutton.tag=3000+i;

        abutton.backgroundColor=[UIColor whiteColor];

        [abutton setTitle:title[i] forState:UIControlStateNormal];

        [abutton addTarget:self action:@selector(HandleButtonAction:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:abutton];

     }   

} 

-(void)HandleButtonAction:(UIButton *)sender{

    switch (sender.tag) {

        case 3000:{

            UITextField *aTextField=(UITextField *)[self.view viewWithTag:300];

            if ([aTextField.text isEqualToString:@"283380371@qq.com"]) {

                UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"验证码已发送到邮箱,请查收!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];

                [alert show];

               alert.delegate=self;

                [alert release];

            }

            else {

                UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"邮箱不正确,请重新输入" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

                [alert show];

                [alert release];

            }       

            break;

        }case 3001:{

            UIView *loginView=[self.view.superview viewWithTag:0001];

            [self.view.superview bringSubviewToFront:loginView];

            break;

        }

        default:

            break;

    } 

}

 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if ((buttonIndex==0)&&[alertView.message isEqualToString:@"验证码已发送到邮箱,请查收!"]) {

        UIView *loginView=[self.view.superview viewWithTag:0001];

        [self.view.superview bringSubviewToFront:loginView];  

    }

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    NSLog(@"%s",__FUNCTION__);

    [textField resignFirstResponder];

    return YES;

}

 第六步:在AppDelegate.m加载主控制器:

#import "AppDelegate.h"

#import "MainViewController.h"

@interface AppDelegate ()<UITextFieldDelegate> 

@end

@implementation AppDelegate

-(void)dealloc{

    [_window release];

    [super dealloc];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    

    self.window.rootViewController = [[[MainViewController alloc] init] autorelease];

    

          return YES;

}

转载于:https://www.cnblogs.com/sxsy-2015/p/4888463.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在信号处理领域,DOA(Direction of Arrival)估计是一项关键技术,主要用于确定多个信号源到达接收阵列的方向。本文将详细探讨三种ESPRIT(Estimation of Signal Parameters via Rotational Invariance Techniques)算法在DOA估计中的实现,以及它们在MATLAB环境中的具体应用。 ESPRIT算法是由Paul Kailath等人于1986年提出的,其核心思想是利用阵列数据的旋转不变性来估计信号源的角度。这种算法相比传统的 MUSIC(Multiple Signal Classification)算法具有较低的计算复杂度,且无需进行特征值分解,因此在实际应用中颇具优势。 1. 普通ESPRIT算法 普通ESPRIT算法分为两个主要步骤:构造等效旋转不变系统和估计角度。通过空间平移(如延时)构建两个子阵列,使得它们之间的关系具有旋转不变性。然后,通过对子阵列数据进行最小二乘拟合,可以得到信号源的角频率估计,进一步转换为DOA估计。 2. 常规ESPRIT算法实现 在描述中提到的`common_esprit_method1.m`和`common_esprit_method2.m`是两种不同的普通ESPRIT算法实现。它们可能在实现细节上略有差异,比如选择子阵列的方式、参数估计的策略等。MATLAB代码通常会包含预处理步骤(如数据归一化)、子阵列构造、旋转不变性矩阵的建立、最小二乘估计等部分。通过运行这两个文件,可以比较它们在估计精度和计算效率上的异同。 3. TLS_ESPRIT算法 TLS(Total Least Squares)ESPRIT是对普通ESPRIT的优化,它考虑了数据噪声的影响,提高了估计的稳健性。在TLS_ESPRIT算法中,不假设数据噪声是高斯白噪声,而是采用总最小二乘准则来拟合数据。这使得算法在噪声环境下表现更优。`TLS_esprit.m`文件应该包含了TLS_ESPRIT算法的完整实现,包括TLS估计的步骤和旋转不变性矩阵的改进处理。 在实际应用中,选择合适的ESPRIT变体取决于系统条件,例如噪声水平、信号质量以及计算资源。通过MATLAB实现,研究者和工程师可以方便地比较不同算法的效果,并根据需要进行调整和优化。同时,这些代码也为教学和学习DOA估计提供了一个直观的平台,有助于深入理解ESPRIT算法的工作原理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值