使用导航栏翻转iphone中的视图

时间:2012-03-30 12:56:06

标签: iphone uiview uiviewcontroller

我想在我的项目中包含Flip视图。我做到了这样,但不能正常工作  和次要视图包含图像视图

UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] 
                               initWithTitle:@"Flip"                                            
                               style:UIBarButtonItemStyleBordered 
                               target:self 
                               action:@selector(flipView)];

self.navigationItem.leftBarButtonItem = flipButton;
UIBarButtonItem *returnButton = [[UIBarButtonItem alloc] 
                               initWithTitle:@"return"                                            
                               style:UIBarButtonItemStyleBordered 
                               target:self 
                               action:@selector(returnView)];

self.navigationItem.leftBarButtonItem = returnButton;

我设置了这样的动作

- (void)flipView{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationOptionTransitionFlipFromTop
                           forView:[self view]
                             cache:YES];
    [self.view addSubview:secondaryView];
    [UIView commitAnimations];
}


- (void)returnView {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                           forView:[self view]
                             cache:YES];
    [secondaryView removeFromSuperview];
    [UIView commitAnimations];
}

2 个答案:

答案 0 :(得分:0)

设置[self.navigationController pushViewController:self.secondaryView animated:YES];

而不是[self.view addSubview:secondaryView];并写

forView:self.navigationController.view cache:NO];

而不是forView:[self view]。 `

答案 1 :(得分:0)

当你放置代码时,肯定没有任何反应,因为你没有机会进行翻转。

尝试移动这些行:

UIBarButtonItem *returnButton = [[UIBarButtonItem alloc] 
                               initWithTitle:@"return"                                            
                               style:UIBarButtonItemStyleBordered 
                               target:self 
                               action:@selector(returnView)];

self.navigationItem.leftBarButtonItem = returnButton;

在flipView内部,动画之后或之前。并复制其他这些行:

UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] 
                               initWithTitle:@"Flip"                                            
                               style:UIBarButtonItemStyleBordered 
                               target:self 
                               action:@selector(flipView)];

self.navigationItem.leftBarButtonItem = flipButton;

在returnView内部。你会看到变化。

我希望能提供帮助!