繁体   English   中英

iOS:如何确定何时绘制UIView?

[英]iOS: How can I decide when UIView gets drawn?

我已在情节UIView板上添加了一个UIView ,并将以下代码成功连接到了它(即,在加载应用程序时,东西会绘制在屏幕上)

#import "UIView+DrawView.h"

@implementation DrawView
- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}

- (void) drawRect:(CGRect)rect
{ //Get the CGContext from this view
    CGContextRef context = UIGraphicsGetCurrentContext();

    //Set the stroke (pen) color
    CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
    //Set the width of the pen mark
    CGContextSetLineWidth(context, 5.0);

    // Draw a line
    //Start at this point
    CGContextMoveToPoint(context, 10.0, 30.0);

    //Give instructions to the CGContext
    //(move "pen" around the screen)
    CGContextAddLineToPoint(context, 310.0, 30.0);
    CGContextAddLineToPoint(context, 310.0, 90.0);
    CGContextAddLineToPoint(context, 10.0, 90.0);

    //Draw it
    CGContextStrokePath(context);
}

@end

但是,我想要手动切换此UIView以显示,但我似乎做不到。 我尝试了以下方法:

  1. UIView设置为在Storyboard中隐藏,然后
  2. 设置DrawView.Hidden = YES; 无济于事,在两种情况下都立即得出;

我希望您可以指导我了解我在这里所缺少的内容。

确保在情节提要中将“自定义类”属性设置为您的类。

暂无
暂无

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

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