首页 文章

隐藏自定义UIView中的图形

提问于
浏览
1

我有该视图GraphViewController的自定义视图图表和视图控制器 . 我正在实现简单的图形 .

这是Chart.h的代码

#import 


@interface Chart : UIView {
    BOOL hideChart;
}
@property BOOL hideChart;
- (void) drawAxesInContext:(CGContextRef)context;
- (void) drawUserChartinContext:(CGContextRef)context;
@end

Chart.m

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctxt = UIGraphicsGetCurrentContext();
    [self drawAxesInContext:ctxt]; 
    [self drawUserChartinContext:ctxt];
}

- (void) drawAxesInContext:(CGContextRef)context {
    CGContextTranslateCTM(context, nullX, nullY);
    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextSetLineWidth(context, 3);
    CGContextBeginPath(context);   

    for (int i=0; i 

 As you can see on screenshot I have uibutton "hide". I want to hide graph (not axes) by pressing this button.
In viewController I created ibaction 

 - (IBAction) hideAndShow {
    self.chart.hideChart = YES;
}
 

 and in view u can see 


    if (hideChart) {
    [[UIColor blackColor] setStroke];
        [self setNeedsDisplay];
        NSLog(@"hide");
    }

但它不起作用,你有什么想法我怎么能这样做? http://dl.dropbox.com/u/866144/Voila_Capture7.png

1 回答

  • 0

    我建议为hideChart添加一个自定义setter,就像这样

    - (void)setHideChart:(BOOL)isHidden {
        self.isHidden = isHidden;
    }
    

相关问题