iPhone:在模态视图选项卡栏中创建滚动图像/文本视图

时间:2011-04-11 14:40:23

标签: iphone xcode view

我刚刚开始使用Objective-C,我正在寻找一种方法来创建一个iPhone应用程序,该应用程序将通过主菜单启动,主菜单可能包含大约8或9个按钮。

当按下按钮时,它将链接到滚动文本视图(包含好几段文本),并在屏幕顶​​部显示一个附带图像,这将作为“返回”按钮返回到主屏幕菜单。我也想看它动画/表现为模态视图(新视图从屏幕底部向上滚动,当按下/按下后退按钮时向下滚动)。

我已经在一个模态视图中工作了标签视图(通过按主菜单中的按钮调出),并且已经找到了如何为每个标签指定自定义图标的方法。我还为每个标签添加了自定义背景。虽然我仍然无法在每个Tab中添加滚动视图,但我可以通过编程方式插入图片和文本。我真的很感激你能给我的任何帮助..

非常感谢!!

·H

    #import <UIKit/UIKit.h>

@interface MasseurViewController : UIViewController {
    UITabBarController *tbc;
}

-(IBAction)showHeadTabBar;
-(void)dismissTabBar;

@property (nonatomic, retain) UITabBarController *tbc;

@end

的.m

#import "MasseurViewController.h"

@implementation MasseurViewController

@synthesize tbc;

//---Implement all the possible Tab Bar views


-(IBAction)showHeadTabBar{

    //---Define Back button

    UIImage *backImage = [UIImage imageNamed:@"headBackButton.png"];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0.0f, 0.0f, backImage.size.width, backImage.size.height);
    [button setImage:backImage forState:UIControlStateNormal];
    [button addTarget:self action:@selector(dismissTabBar) forControlEvents:UIControlEventTouchUpInside];

    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.frame = CGRectMake(0.0f, 0.0f, backImage.size.width, backImage.size.height);
    [button2 setImage:backImage forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(dismissTabBar) forControlEvents:UIControlEventTouchUpInside];

    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    button3.frame = CGRectMake(0.0f, 0.0f, backImage.size.width, backImage.size.height);
    [button3 setImage:backImage forState:UIControlStateNormal];
    [button3 addTarget:self action:@selector(dismissTabBar) forControlEvents:UIControlEventTouchUpInside];

    //------------************TABS**************-------------------
    //-------------------------------------------------------------

    //---------------Declare View Controllers-----------
    //---------------------------TAB 1
    UIViewController *blueController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    blueController.title = @"Blue";
    blueController.tabBarItem.image = [UIImage imageNamed:@"tabBar1.png"];
    //---Add tabs & Tab names
    [blueController.view addSubview:button];
    blueController.view.backgroundColor = [UIColor whiteColor];
    blueController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"mainMenuBKG.png"]];   


    //----TAB 2
    UIViewController *redController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    redController.view.backgroundColor = [UIColor grayColor];
    redController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"shouldersImage1.png"]];    



    //----TAB 3
    UIViewController *greenController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    greenController.view.backgroundColor = [UIColor greenColor];
    //--------------------------------------------------


    //---Instantiate tab bars

    tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil];

    //---Create array of tabs
    tbc.viewControllers = [NSArray arrayWithObjects:blueController, redController, greenController, nil];

    //---Select starting tab
    tbc.selectedViewController = blueController;

    //--------------------------------------------------


    //---Add tabs & Tab names

    [redController.view addSubview:button2];
    redController.title = @"Red";

    [greenController.view addSubview:button3];
    greenController.title = @"Green";


    //---Release Tab views
    [blueController release];
    [redController release];
    [greenController release];
    [self presentModalViewController:tbc animated:YES];


}

//---Code to dismiss Tab Bars
- (void)dismissTabBar {
    [self dismissModalViewControllerAnimated:YES];
    [tbc release];
}


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


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


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end

2 个答案:

答案 0 :(得分:0)

你的问题过于笼统,不能提供一个好的答案,但我会尽力指出你正确的方向。

您不必为每个按钮创建单独的.h / .m / .xib - 您可能希望所有按钮的主菜单页面由单个视图控制器类(.h,.m)控制在单个.xib文件中创建所有按钮可能会很方便。

您为每个按钮的操作创建的视图取决于您希望它执行的操作。如果其中3个只显示图像,则可以重新使用名为displayImageView的类。

我建议您使用单个按钮和操作让您的应用使用单个主视图,然后找出如何将其扩展为8或9个操作。

最后,我认为你有很多阅读要做。 Here是一个很好的起点。祝你好运。

答案 1 :(得分:0)

在我看来,您完全适合使用导航控制器。 您的“主要”视图应为UITableView,而不是8或9按钮。然后,每次用户选择此表中的行时,都会使用正确的文本推送详细视图。这意味着你不需要一个图像作为“后退”按钮,因为这将由导航控制器自动提供(它是左上角的这个箭头形状的后退按钮)。

尝试阅读有关iPhone基本应用程序设计模式的更多信息(this是一个良好的开端),如果您需要一些示例代码,请尝试使用CoreDataBooks或类似内容。

祝你好运!