Alp
Alp

Reputation: 1893

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

to use same visibility functions in android such as

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.

Thank you.

Upvotes: 0

Views: 589

Answers (1)

Ashish Kakkad
Ashish Kakkad

Reputation: 23892

In WatchKit you can not remove the objects programmatically.

You can use setHidden: property

Hides or shows the interface object in your user interface.

func setHidden(_ hidden: Bool)

A Boolean value indicating the visibility of the object. Specify true to hide the object. Specify false to show it.

Discussion

When you hide or show an object in your interface, WatchKit makes a note to update the layout during the next refresh cycle. During that cycle, WatchKit adjusts the layout to display only the currently visible objects.

Reference Questions :

Can I create a WatchKit app without a storyboard (entirely in code)?

Create imageView programmatically in Watch Kit

Upvotes: 1

Related Questions