【问题标题】:Flip view in iphone with navigation bar使用导航栏在 iphone 中翻转视图
【发布时间】:2012-03-30 12:56:05
【问题描述】:

我想在我的项目中包含翻转视图。我做到了,但无法正常工作 并且辅助视图包含一个图像视图

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];
}

【问题讨论】:

  • 那么到底是什么问题..?
  • 你调用 self.navigationItem.leftBarButtonItem = flipButton;然后你调用 self.navigationItem.leftBarButtonItem = returnButton;所以,我的理解是,你只有 returnButton,这意味着 -flipView 永远不会被调用。
  • @AdilSoomro 翻转按钮不可见返回按钮可见 insted 翻转.. 每次执行返回视图操作时
  • @Canopus 是一样的.. 怎么做才能首先获得翻转按钮并在翻转后返回按钮..

标签: iphone uiview uiviewcontroller


【解决方案1】:

当然,当您输入代码时,什么都不会发生,因为您没有给机会进行翻转。

尝试移动这些行:

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 内部。你会看到变化。

希望对你有所帮助!

【讨论】:

    【解决方案2】:

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

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

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

    而不是forView:[self view]。 `

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多