iOS equivalent for Android View.GONE visibility mode

前端 未结 13 748
臣服心动
臣服心动 2020-12-12 19:22

I\'m developing an app for iOS and I\'m using the Storyboard with AutoLayout ON. One of my view controllers has a set of 4 buttons, and in certain circumstances i would like

13条回答
  •  一整个雨季
    2020-12-12 20:15

    As my research has shown, not even AutoLayout can help you. You have to manually replace the views affected by the optionally shown component (in my case, all the views to the bottom of the optional view, but you I am sure you can adapt this to handle all the buttons to the right of your optional button):

    - (IBAction)toggleOptionalView:(id)sender {
        if (!_expanded) {
            self.optionalView.frame = CGRectMake(self.optionalView.frame.origin.x, self.optionalView.frame.origin.y, self.optionalView.frame.size.width, _optionalHeight);
            self.bottomView.frame = CGRectMake(self.bottomView.frame.origin.x, self.bottomView.frame.origin.y+_optionalHeight, self.bottomView.frame.size.width, self.bottomView.frame.size.height);
            _expanded = YES;
        } else {
            self.optionalView.frame = CGRectMake(self.optionalView.frame.origin.x, self.optionalView.frame.origin.y, self.optionalView.frame.size.width, 0);
            self.bottomView.frame = CGRectMake(self.bottomView.frame.origin.x, self.bottomView.frame.origin.y-_optionalHeight, self.bottomView.frame.size.width, self.bottomView.frame.size.height);
            _expanded = NO;
    
        }
    }
    

    It is advisable not to hard-code the height/width of the optional components, otherwise your code breaks every time you edit the XIB/Storyboard. I have a field float _optionalHeight which I set in viewDidLoad, so it is always up to date.

提交回复
热议问题