2013-05-31 97 views
0

不會說謊,我試圖按照一本書中的教程,我無法通過這個警告。不兼容的指針類型初始化'CGContextRef *'

Incompatible pointer types initializing 'CGContextRef *' (aka 'struct CGContext **') with an expression of type 'CGContextRef' (aka 'struct CGContext *')

有問題的行是:CGContextRef *imageContext = UIGraphicsGetCurrentContext();

- (IBAction)hide:(id)sender { 
    CGContextRef *imageContext = UIGraphicsGetCurrentContext(); 
    if (_myIcon.alpha == 1) { 
     [UIView beginAnimations:nil context:imageContext]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
     [UIView setAnimationDuration:3]; 
     [UIView setAnimationDelegate:self]; 
     _myIcon.alpha = 0.0; 
     [_hideButton setTitle:@"Show" forState:UIControlStateNormal]; 
    } else if (_myIcon.alpha == 0.0) { 
     [UIView beginAnimations:nil context:imageContext]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
     [UIView setAnimationDuration:3]; 
     [UIView setAnimationDelegate:self]; 
     _myIcon.alpha = 1; 
     [_hideButton setTitle:@"Hide" forState:UIControlStateNormal]; 
    } 

    [UIView commitAnimations]; 

} 
+0

順便說一句 - 你需要一本新書。不鼓勵使用'UIView beginAnimations:context:'和'UIView commitAnimations'。使用「UIView」的更新的基於塊的動畫方法要好得多。 – rmaddy

+0

@rmaddy版權所有2013 ...這很糟糕。 – nipponese

回答

0

CGContextRef不是類。你不需要指針。更改此:

CGContextRef *imageContext = UIGraphicsGetCurrentContext(); 

到:

CGContextRef imageContext = UIGraphicsGetCurrentContext(); 

看的文檔爲UIGraphicsGetCurrentContext功能。返回類型是CGContextRef,而不是CGContextRef *

+0

謝謝,這是本書中的一個錯字。 – nipponese

+0

看看這本書的網站。通常有一個勘誤部分指出錯誤。 – rmaddy

相關問題