Force NSView to redraw programmatically

落花浮王杯 提交于 2019-12-03 14:22:45

I found it, the code is just fine and no need to call any redraw method, the only problem Any UI action need to be done in the MAIN thread

so the final code will be:

dispatch_async( dispatch_get_main_queue(), ^{
    if (appState == 1) {
        [self.splitView setFrameSize:CGSizeMake(self.splitView.frame.size.width, self.view.frame.size.height - 250)];

        [self.mySubView1 setHidden:NO];
        [self.mySubView2 setHidden:YES];
    }
    else
    {
        [self.splitView setFrameSize:CGSizeMake(self.splitView.frame.size.width, self.view.frame.size.height - 70)];

        [self.mySubView1 setHidden:YES];
        [self.mySubView2 setHidden:NO];
    }
});

Thanks, guys.

doing a subview remove or add operation will automatically call setNeedsDisplay:YES so it's no surprise that calling it manually is having no effect.

some things to check:

  1. Check your view properties for nil values. I see you are removing the view which will cause the superview to release it and if you aren't retaining it with a strong property (or elsewhere) it will be deallocated.
  2. Be sure that you aren't fighting autolayout. turn off autolayout temporarily to confirm it is not causing your problem.
  3. you are only setting the frame size. you need to make sure it has the expected origin as well.

Also if you are removing the view you don't need to bother calling setHidden:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!