当再次出现视图时,不会调用drawRect

时间:2019-06-07 10:31:55

标签: ios objective-c drawrect

我像drawRect一样使用viewWillAppear,并检查了一些状态并为标签设置了一些值。

iOS 12和更高版本上可以。但是, iOS 11.3和更早版本未调用drawRect

因此,我找到了解决方法。我正在使用willMoveToWindow方法执行我在viewWillAppear中所做的事情

   @implementation AFEBigLapTimerWidgetView
   - (void)drawRect:(CGRect)rect {

        if (self.viewModel.isLapTimerServiceStarted) {
            [self setLapTimerButtoStateWithState:AFELapimerButtonStateLap];
            [self.viewsToHide enumerateObjectsUsingBlock:^(UIView *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                obj.hidden = NO;
            }];
            [self.viewModel updateLabelsForStartedService];
        } else if (self.viewModel.isCountdownOngoing) {
            // Check if countdown is ongoing
            self.countdownLabel.hidden = NO;
            self.countdownLabel.alpha = 1.0;
            [self setLapTimerButtoStateWithState:AFELapimerButtonStateLap];
            [self countdownValueChanged:self.viewModel.countdownValue];
            [self.viewsToHide enumerateObjectsUsingBlock:^(UIView *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                obj.hidden = YES;
            }];
        } else {
            [self setupDefaults];
        }
    }
    @end

0 个答案:

没有答案