如何从标签栏控制器以模态方式呈现视图,以便视图覆盖实际视图?
我想用相机构建一个视图。像“WhatsApp”或“Instagram”这样的东西,中间有一个按钮,用户可以点击并显示摄像机视图。
此外,用户应该在单击关闭按钮之前移动他之前的标签。
答案 0 :(得分:8)
我必须在我目前正在构建的应用中实现类似的功能,而且相对简单易行,您需要实现UITabBarController
的委托方法才能实现实现这一目标。
您需要实现的委托方法是:
tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool
从此方法返回false将阻止选项卡控制器选择选项卡,然后您只需要实现自己的逻辑以编程方式显示UIViewController
。
以下是一个例子:
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
// If your view controller is emedded in a UINavigationController you will need to check if it's a UINavigationController and check that the root view controller is your desired controller (or subclass the navigation controller)
if viewController is YourViewControllerClass {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let controller = storyboard.instantiateViewController(withIdentifier: "storyboardID") as? YourViewControllerClass {
controller.modalPresentationStyle = .fullScreen
self.present(controller, animated: true, completion: nil)
}
return false
}
// Tells the tab bar to select other view controller as normal
return true
}
我没有测试上面的代码,因为我的实现略有不同并且有更多变量。一般原则是一样的。
让我知道你是如何继续的,如果有必要,我会更新答案。
答案 1 :(得分:3)
假设您符合UITabBarControllerDelegate,您可以实施:
X = np.vstack( (car_features, notcar_features) ).astype(np.float64)
print('X.shape',X.shape)
# Fit a per-column scaler
X_scaler = StandardScaler().fit(X)
# Apply the scaler to X
scaled_X = X_scaler.transform(X)
答案 2 :(得分:0)
var collideRect=function(obj1, obj2){
var x1=obj1.x,y1=obj1.y,x2=obj2.x, y2=obj2.y;
var b1=obj1.breadth,h1=obj1.height;
var b2=obj2.breadth,h2=obj2.height;
var xCollide, yCollide;
// determine if the x values are closer than half the breadth of each rectangle to each other
if(x1+b1/2>x2-b2/2||x1-b1/2<x2+b2/2){xCollide=true};
// determine if the y values are closer than half their heights from one another
if(y1+h1/2>y2-h2/2||y1-h1/2<y2+h2/2){yCollide=true};
if(xCollide&&yCollide){
console.log(JSON.stringify(obj1)+". "+JSON.stringify(obj2)) ;
return true;
};
}