简体   繁体   English

如何快速从Apple Watch / Watchkit的Superview中删除视图

[英]how to remove view from superview in apple watch / watchkit in swift

to use same visibility functions in android such as 在android中使用相同的可见性功能,例如

1) android:visibility="gone" // used to hide the control and as well as space
  (or)
  CONTROLNAME.setVisibility(View.GONE);
2)  android:visibility="invisible" // used to hide the control but it will take space
  (or)
  CONTROLNAME.setVisibility(View.INVISIBLE);

which is in this question for apple watch application 这是这个问题对苹果手表的应用

i have tried code below 我在下面尝试过代码

splashscreenImage.removeFromSuperView()

and

[self.splashscreenImage addConstraint:[NSLayoutConstraint constraintWithItem:self.captchaView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]];

also

[splashscreenImage removeFromSuperview]

non of above has worked for me. 以上都不对我有用。 Please tell me code to remove view from super for a class which is extended from WKInterfaceController. 请告诉我代码,以从WKInterfaceController扩展的类的super中删除视图。

Thank you. 谢谢。

In WatchKit you can not remove the objects programmatically. 在WatchKit中,您无法以编程方式删除对象。

You can use setHidden: property 您可以使用setHidden:属性

Hides or shows the interface object in your user interface. 在用户界面中隐藏或显示界面对象。

func setHidden(_ hidden: Bool) func setHidden(_隐藏:布尔)

A Boolean value indicating the visibility of the object. 一个布尔值,指示对象的可见性。 Specify true to hide the object. 指定true可以隐藏对象。 Specify false to show it. 指定false以显示它。

Discussion 讨论区

When you hide or show an object in your interface, WatchKit makes a note to update the layout during the next refresh cycle. 当您在界面中隐藏或显示对象时,WatchKit会记下要在下一个刷新周期中更新布局的注释。 During that cycle, WatchKit adjusts the layout to display only the currently visible objects. 在该周期内,WatchKit调整布局以仅显示当前可见的对象。

Reference Questions : 参考问题:

Can I create a WatchKit app without a storyboard (entirely in code)? 我可以创建没有情节提要(完全用代码编写)的WatchKit应用程序吗?

Create imageView programmatically in Watch Kit 在Watch Kit中以编程方式创建imageView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM