通过TabBar调情两个视图

时间:2011-08-27 10:44:59

标签: iphone view methods uitabbar

这是我的代码:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] 
                              initWithTitle:@"Speichern" 
                              style:UIBarButtonItemStylePlain target:self 
                              action:@selector(SaveSettings)]; 
self.navigationItem.rightBarButtonItem = newButton; 
[newButton release]; 

ensStyleControl.selectedSegmentIndex = [SettingsHandler GetENSStyle];

UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 376, 320, 44)];
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"Allgemein" image:[UIImage imageNamed:@"crops.png"] tag:0];
UITabBarItem *item2  = [[UITabBarItem alloc] initWithTitle:@"ENS" image:[UIImage imageNamed:@"crops.png"] tag:1];

[item1 performSelectorOnMainThread:@selector(ShowGeneralSetting) withObject:nil waitUntilDone:NO];

[item2 performSelectorOnMainThread:@selector(ShowENSSetting) withObject:nil waitUntilDone:NO];


NSArray *items = [NSArray arrayWithObjects:item1,item2, nil];
[tabBar setItems:items animated:YES];
[tabBar setSelectedItem:nil];
tabBar.delegate=self;

[self.view addSubview:tabBar];
}

- (void)ShowENSSetting
{
    //Show View1
}

- (void)ShowGeneralSetting
{
    //Show View2
}

如何在方法中翻转View1和View2?

1 个答案:

答案 0 :(得分:1)

- (void)ShowENSSetting{
//assume    view1.tag=11;
    [UIView transitionWithView:self.view duration:2.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^(void) {

        if (![self.view viewWithTag:11]) {
            view1.tag=11;
            [self.view addSubview:view1];

        }

        else {
            [self.view bringSubviewToFront:[self.view viewWithTag:11]];
        }




    } completion:^(BOOL finished) {

        NSLog(@"ENSSetting active");

    }];




}


- (void)ShowGeneralSetting{

        //assume    view2.tag=22;

    [UIView transitionWithView:self.view duration:2.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^(void) {

        if (![self.view viewWithTag:22]) {
            view2.tag=22;               
            [self.view addSubview:view2];

        }

        else {
            [self.view bringSubviewToFront:[self.view viewWithTag:22]];
        }




    } completion:^(BOOL finished) {

        NSLog(@"GeneralSetting active");

    }];





}