如何从一个点移动uiview ios
我正在创建一个应用程序,我只想从一侧移动uview, 我必须更改一点(-y点)。如何从一个点移动uiview ios
目前来看显示为
:
但我想这一点:
我已经试过这样:
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);
使用具有所需形状的图像或者在实验室后面画一层具有所需形状埃尔斯
编辑:
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];
我该如何绘制图层?我在故事板中使用了uiview。 – Optimistic
thnks但它不支持,如果我改变oriantation。 :( – Optimistic
它并没有设置到视图的底部?我必须更改它以将其设置到self.view的底部? – Optimistic
使用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);
Thnk u Frndu。:) – Optimistic
创建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
我已经移除素标记从旋转视图并将它们放在主视图上。 – Optimistic
@MidhunMP:检查更新的问题。请帮助我。 – Optimistic
您可以使用CAShapeLayer和CATextLayer来做同样的事情,也请检查CoreText和NSAttributedString。 –