3部分结构iPad应用程序

时间:2013-12-20 07:27:29

标签: ios ipad

我想制作一个带有上下部分的iPad应用程序。按钮将位于下部,单击时,只有中间部分会发生变化。我必须使用什么样的结构?我没有标准的窗口,标签和按钮的问题,但我不知道如何确保中间部分不会改变。

1 个答案:

答案 0 :(得分:0)

您可以在屏幕上使用3个UIViews,第1个屏幕上层,第2个屏幕中间层,第3个屏幕下层屏幕,它可以为您提供所需的结果。

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIView *view1;
@property (weak, nonatomic) IBOutlet UIView *view2;
@property (weak, nonatomic) IBOutlet UIView *view3;
@property (weak, nonatomic) IBOutlet UIButton *btnSubmit;
@property (weak, nonatomic) IBOutlet UILabel *lblClick;
- (IBAction)btnClick:(id)sender;
@end

ViewController.m

@implementation ViewController
int i=1;
@synthesize view1;
@synthesize view2;
@synthesize view3;
@synthesize btnSubmit;
@synthesize lblClick;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

    - (void)viewDidLoad
    {
        [super viewDidLoad];
            // Do any additional setup after loading the view, typically from a nib.
    }

    - (void)viewDidUnload
    {
        [self setView1:nil];
        [self setView2:nil];
        [self setView3:nil];
        [self setBtnSubmit:nil];
        [self setLblClick:nil];
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    }

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    }

    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    }

    - (void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }

    - (IBAction)btnClick:(id)sender 
    {

        btnSubmit.tag = i++;
        lblClick.text = [NSString stringWithFormat:@"%d",i];
        if(i%2 == 0)
        {
            view2.backgroundColor = [UIColor blueColor];
        }
        else
        {
            view2.backgroundColor = [UIColor greenColor];
        }
    }
    @end

上面的例子只是在1个viewcontroller中使用3个视图的想法,在这个例子中取3个视图,其中第1个视图只是空白,2个视图有标签,显示在view3中点击按钮的值。并且在点击按钮上是标签值甚至然后view2背景颜色被改变ti蓝色是vaqlue是奇数然后它变成绿色。 在视图3中有jus按钮。