TransitionFromView 删除以前的视图 [英] TransitionFromView removes previous view

查看:26
本文介绍了TransitionFromView 删除以前的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中的视图之间转换时,我在使用 TransitionfromView 时遇到问题.

I am having problems using TransitionfromView while transitioning between views in my app.

设置

这是视图控制器的基本设置.它有两个视图.一个 MKMapView 和一个 UITableView.当按下切换按钮时,它应该在地图和表格之间交替视图.

This is the basic setup of the View Controller. It has two views in it. A MKMapView and a UITableView. When the toggle button is pressed, it is supposed to alternate views between map and table.

这是我的 *.h 文件

This is my *.h file

@interface BrowseBeaconsViewController : UIViewController <UITableViewDelegate, MKMapViewDelegate, UITableViewDataSource, CLLocationManagerDelegate >
{

__weak IBOutlet UIBarButtonItem *refreshBeacons;
__weak IBOutlet UIBarButtonItem *toggleView;
MKMapView* beaconMapView;
__weak IBOutlet UITableView* beaconTableView;
}

所以tableview来自storyboard,而mapview是在程序中创建的.

So the tableview comes from the storyboard while mapview is created in the program.

问题

[UIView transitionFromView:beaconTableView toView:beaconMapView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {}];

当我从 MapView 的 TableView 转换时,tableview 的值为空(0x0000000).我确实理解 transitionfromview 的行为是从父视图中删除视图.但是当我尝试在转换后将 tableview 添加为子视图时,它不起作用,因为该值为 null.所以我的问题是如果视图为空,如何在转换后添加 tableview?

When I transition from TableView from MapView the value of the tableview is null(0x0000000). I do understand the behaviour of the transitionfromview is to remove the view from the parent view. But when I try add the tableview as a subview after the transition it doesn't work, since the value is null. So my question is how do I add the tableview after the transition if the view is nulled?

PS:如果这是一个简单的问题,我深表歉意,但我是 iOS 编程新手,在发布此问题之前确实尝试查看论坛.

PS: I apologize if this is a simple question, but I am new to iOS programming and did try to look in the forums before posting this question.

推荐答案

来自该方法的文档:

"默认情况下,视图层次结构中的 fromView 视图被 toView 中的视图替换.如果两个视图都已经是视图层次结构的一部分,您可以在 options 参数中包含 UIViewAnimationOptionShowHideTransitionViews 选项来简单地隐藏或显示它们."

"By default, the view in fromView is replaced in the view hierarchy by the view in toView. If both views are already part of your view hierarchy, you can include the UIViewAnimationOptionShowHideTransitionViews option in the options parameter to simply hide or show them."

因此,如果您希望保留两个视图,请将信标映射视图添加到视图层次结构中,并包含 UIViewAnimationOptionShowHideTransitionViews 选项.

So, if you want both views to remain, add the beaconMapView to the view hierarchy, and include the UIViewAnimationOptionShowHideTransitionViews option.

这篇关于TransitionFromView 删除以前的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆