如何从一点ios移动uiview

时间:2014-01-22 10:33:04

标签: ios iphone objective-c uiview rotation

我正在创建一个应用程序,我只想从一侧移动uiview, 我必须改变一点(-y点)。

目前视图显示为

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);

3 个答案:

答案 0 :(得分:0)

使用具有所需形状的图像或在具有所需形状的标签后面绘制图层

修改

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];

答案 1 :(得分:0)

使用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);

答案 2 :(得分:0)

创建UIViwe类绘制形状并添加到baseview

@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