简体   繁体   English

如何从一点ios移动uiview

[英]how to move uiview from one point ios

I am creating a app where i want to move uiview from only one side, I have to change the one point (-y point). 我正在创建一个应用程序,我只想从一侧移动uiview,我必须更改一个点(-y点)。

Currently view displayed as 当前视图显示为

: 在此处输入图片说明

But I want this : 但是我想要这个:

在此处输入图片说明

i have tried this : 我已经试过了

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

Use an Image with desired shape or draw a layer behind the labels with desired shape 使用具有所需形状的图像或在具有所需形状的标签后面绘制一层

EDIT: 编辑:

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

Use CAShapeLayer for achieve this 使用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);

Create UIViwe class draw shape and add in baseview 创建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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM