【问题标题】:Switching View within a ViewController在 ViewController 中切换视图
【发布时间】:2011-07-20 07:56:33
【问题描述】:

我正在构建一个需要我在 5 个视图之间切换的应用程序,并且所有这些视图都在一个视图控制器类中。我可以使用addSubviewremoveFromSuperview 方法来切换它们,但问题是我想在当前视图向左移出而下一个视图从右移入的情况下对其进行动画处理。

我尝试使用this thread,但无法获得所需的结果。

我们将不胜感激任何形式的帮助。

提前致谢!!

【问题讨论】:

  • 5 个视图是全屏的?您想添加一个过渡并添加下一个视图,如 pushViewController?
  • 是这样的

标签: iphone animation uiview


【解决方案1】:

您可以使用以下方法为视图设置动画:

[UIView animateWithDuration:0.8f animations: 
^{
  // and of course you can edit the duration according to your need 
  // Change Alpha value of the view or set it to hidden    
  // you can also change the frame; which will make the view change it position with animation to the new provided frame. 
}
completion: ^(BOOL finished)
{
 // Your Code here; if you want to add other animation on the end of the proccess.
}

};

【讨论】:

    【解决方案2】:

    你可以用这个

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.5];
        CGAffineTransform transform = CGAffineTransformMakeTranslation(xOffSet, yoffSet);
        myView.transform = transform;
        [UIView commitAnimations];
    

    希望对您有所帮助....

    【讨论】:

    • 感谢您的回复......它第一次工作......但是当我回到父视图并再次尝试重新动画整个事情时没有任何反应。触发事件的按钮是 UITableView 的一个单元格......请建议我出路......谢谢
    猜你喜欢
    • 2017-02-20
    • 2020-12-24
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    相关资源
    最近更新 更多