2014-01-22 57 views
0

我正在創建一個應用程序,我只想從一側移動uview, 我必須更改一點(-y點)。如何從一個點移動uiview ios

目前來看顯示爲

enter image description here

但我想這一點:

enter image description here

我已經試過這樣:

UIView *viewRed=(UIView*)[self.view viewWithTag:11]; 
    float angle = M_PI/10; //rotate 180°, or 1 π radians 
    viewRed.layer.transform = CATransform3DMakeRotation(angle, 0, 0.0, 1.0); 
+0

我已經移除素標記從旋轉視圖並將它們放在主視圖上。 – Optimistic

+0

@MidhunMP:檢查更新的問題。請幫助我。 – Optimistic

+0

您可以使用CAShapeLayer和CATextLayer來做同樣的事情,也請檢查CoreText和NSAttributedString。 –

回答

1

使用具有所需形狀的圖像或者在實驗室後面畫一層具有所需形狀埃爾斯

編輯:

UIBezierPath *aPath = [UIBezierPath bezierPath]; 
    // Set the starting point of the shape. 
[aPath moveToPoint:CGPointMake(0.0, 300)]; 

// Draw the lines. 
[aPath addLineToPoint:CGPointMake(self.view.frame.size.width, 300.0)]; 

[aPath addLineToPoint:CGPointMake(self.view.frame.size.width, 200.0)]; 

[aPath addLineToPoint:CGPointMake(0.0, 120.0)]; 


CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
shapeLayer.path = aPath.CGPath; 
shapeLayer.fillColor = [[[UIColor redColor] colorWithAlphaComponent:0.5] CGColor]; 
[self.view.layer addSublayer:shapeLayer]; 
+0

我該如何繪製圖層?我在故事板中使用了uiview。 – Optimistic

+0

thnks但它不支持,如果我改變oriantation。 :( – Optimistic

+0

它並沒有設置到視圖的底部?我必須更改它以將其設置到self.view的底部? – Optimistic

1

使用CAShapeLayer爲實現這一

 CGMutablePathRef path = CGPathCreateMutable(); 
    CGPathMoveToPoint(path,NULL,0.0,200.0); 
    CGPathAddLineToPoint(path, NULL, 320.0f, 250.0f); 
    CGPathAddLineToPoint(path, NULL, 320.0f, 367.0f); 
    CGPathAddLineToPoint(path, NULL, 0.0f, 367.0f); 
    CGPathAddLineToPoint(path, NULL, 0.0f, 200.0f); 


    CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
    [shapeLayer setPath:path]; 
    [shapeLayer setFillColor:[[UIColor redColor] CGColor]]; 
    [shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]]; 
    [shapeLayer setBounds:CGRectMake(0.0f, 0.0f, 160.0f, 480)]; 
    [shapeLayer setAnchorPoint:CGPointMake(0.0f, 0.0f)]; 
    [shapeLayer setPosition:CGPointMake(0.0f, 0.0f)]; 
    [[[self view] layer] addSublayer:shapeLayer]; 

    CGPathRelease(path); 
+0

Thnk u Frndu。:) – Optimistic

0

創建UIViwe類繪製形狀,並添加基本視圖

@interface ShapeView : UIView 

@end 

@implementation fractalTriangel 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
} 
    return self; 
} 

- (void)drawRect:(CGRect)rect 
{ 
CGContextRef ctx = UIGraphicsGetCurrentContext(); 

    CGContextBeginPath(ctx); 
    CGContextMoveToPoint (ctx, point1.x,point1.y); 
    CGContextAddLineToPoint(ctx, point2.x,point2.y); 
    CGContextAddLineToPoint(ctx, point3.x,point3.y); 
    CGContextAddLineToPoint(ctx, point4.x,point4.y); 
    CGContextClosePath(ctx); 

    CGContextSetRGBFillColor(ctx, 1,1, 1, 1);//set color 

    CGContextFillPath(ctx); 
} 


@end 
相關問題