2013-07-08 80 views
0

我有一個應用程序,每次用戶繪製一個手繪圓時,程序都會將/ init初始化爲繪製CAShapelayer圓的圓類(uiview),而不是由用戶繪製。 現在我想,當用戶將按超級查看按鈕時,繪製的圓的alpha將會改變。 這是相關代碼:iOS:動態更改UIView

blueCircleView =[[ASFBlueCircle alloc]initWithFrame:CGRectMake(startPoint.x-10, startPoint.y-20, 60, 60)]; 

[self addSubview:blueCircleView]; 

,並從類的初始化代碼:

-(id)initWithFrame:(CGRect)frame{ 
self = [super initWithFrame:frame]; 
if (self) { 
    // Initialization code 

    self.backgroundColor=[UIColor clearColor]; 
    UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 75, 75)]; 
    blueCircleLayer = [CAShapeLayer layer]; 
    blueCircleLayer.path = circle.CGPath; 
    blueCircleLayer.strokeColor = [UIColor blueColor].CGColor; 
    blueCircleLayer.fillColor = [UIColor clearColor].CGColor; 
    blueCircleLayer.shadowColor =[UIColor blackColor].CGColor; 
    blueCircleLayer.shadowOffset = CGSizeMake(0.0f, 5.0f); 
    blueCircleLayer.shadowOpacity = 0.7f; 
    blueCircleLayer.lineWidth = 7.0; 

    [self.layer addSublayer:blueCircleLayer]; 
+0

那麼,這是什麼問題?你做了什麼,出了什麼問題?向我們展示捕捉用戶手勢的一些代碼,e.q. –

回答

0

在ASFBlueCircle.h添加屬性 @property CAShapeLayer * blueCircleLayer;

在init中,addsublayer寫入以下行之後 self.blueCircleLayer = blueCircleLayer;

並在按鈕被按下時調用的方法 self.blueCircleLayer.color = [UIColor colorWithRed:red green:green blue:blue alpha:alpha] .CGColor;

用你想要的紅色,綠色,藍色,alpha值。

+0

嗯,它有幫助嗎? – johnyu