我正在拼贴应用程序和拼贴视图我需要设置框架的边框宽度和角半径,视图将是另一个视图的子图层,后视图将背景颜色设置为棕色。我能够更改边框宽度和角半径使用滑块,但在这之后,我在视图周围得到小的微小边框白线(像阴影)。我尝试使用阴影不透明但它不起作用。下面是我的代码。
- (IBAction)sliderActionToChangeCornerWidthOfView:(id)sender {
UISlider *slider = (UISlider*)sender;
int i=0;
for (CollageView *viewCollage in self.collageView.subviews) {
if ([viewCollage isKindOfClass:[CollageView class]]) {
self.appDelg.borderWidth = slider.value/2;
if ([[array objectAtIndex:i] valueForKey:@"path"]!=nil) {
if (arrayOfLayers.count > 0) {
[arrayOfLayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
}
NSMutableArray *arrayToRadius = [[NSMutableArray alloc] init];
arrayToRadius = [arrayToRadius getArrayOfCollages:_collageView.bounds.size numberOfCollages:numberOfCollages];
NSArray *arrayToChangeCornerRadius=[[[arrayToRadius objectAtIndex:btnClickIndex] valueForKey:@"values"] objectAtIndex:0];
UIBezierPath *starPath=[[arrayToChangeCornerRadius objectAtIndex:i] valueForKey:@"path"];
CAShapeLayer *cornerMaskLayer = [CAShapeLayer layer];
[cornerMaskLayer setPath:starPath.CGPath];
viewCollage.layer.mask = cornerMaskLayer;
CAShapeLayer *strokeLayer = [CAShapeLayer layer];
strokeLayer.path = starPath.CGPath;
strokeLayer.lineWidth = self.appDelg.borderWidth;
strokeLayer.lineJoin = kCALineJoinRound;
// the stroke splits the width evenly inside and outside,
strokeLayer.fillColor = [UIColor clearColor].CGColor;
if (patternImage!=nil) {
strokeLayer.strokeColor = [UIColor colorWithPatternImage:[self patterDraw]].CGColor;
}
else
{
strokeLayer.strokeColor = borderColour.CGColor;
}
CGRect rect=CGPathGetBoundingBox(starPath.CGPath);
[viewCollage layoutIfNeeded];
strokeLayer.shadowOpacity = 0.0;
[arrayOfLayers addObject:strokeLayer];
[viewCollage.layer addSublayer:strokeLayer];
NSLog(@"value : %@", NSStringFromCGRect(viewCollage.frame) );
}
else
{
if (patternImage!=nil) {
viewCollage.layer.borderColor = [UIColor colorWithPatternImage:[self patterDraw]].CGColor;
}
else
{
viewCollage.layer.borderColor = borderColour.CGColor;
}
viewCollage.layer.borderWidth = slider.value/2;
}
i++;
}
}
}
- (IBAction)sliderActionToChangeCornerRadius:(id)sender {
UISlider *slider = (UISlider*)sender;
int i = 0;
for (CollageView *viewCollage in self.collageView.subviews) {
if ([viewCollage isKindOfClass:[CollageView class]]) {
self.appDelg.cornerRadiusValue = slider.value;
if ([[array objectAtIndex:i] valueForKey:@"path"]!=nil) {
if (arrayOfLayers.count > 0) {
[arrayOfLayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
}
NSMutableArray *arrayToRadius = [[NSMutableArray alloc] init];
arrayToRadius = [arrayToRadius getArrayOfCollages:_collageView.bounds.size numberOfCollages:numberOfCollages];
NSArray *arrayToChangeCornerRadius=[[[arrayToRadius objectAtIndex:btnClickIndex] valueForKey:@"values"] objectAtIndex:0];
UIBezierPath *starPath=[[arrayToChangeCornerRadius objectAtIndex:i] valueForKey:@"path"];
CAShapeLayer *cornerMaskLayer = [CAShapeLayer layer];
[cornerMaskLayer setPath:starPath.CGPath];
viewCollage.layer.mask = cornerMaskLayer;
CAShapeLayer *strokeLayer = [CAShapeLayer layer];
strokeLayer.path = starPath.CGPath;
strokeLayer.lineWidth = self.appDelg.borderWidth;
strokeLayer.lineJoin = kCALineJoinRound;
// the stroke splits the width evenly inside and outside,
strokeLayer.fillColor = [UIColor clearColor].CGColor;
if (patternImage!=nil) {
strokeLayer.strokeColor = [UIColor colorWithPatternImage:[self patterDraw]].CGColor;
}
else
{
strokeLayer.strokeColor = borderColour.CGColor;
}
CGRect rect=CGPathGetBoundingBox(starPath.CGPath);
[viewCollage layoutIfNeeded];
[arrayOfLayers addObject:strokeLayer];
[viewCollage.layer addSublayer:strokeLayer];
NSLog(@"value : %@", NSStringFromCGRect(viewCollage.frame) );
}
else
{
viewCollage.layer.cornerRadius = slider.value;
}
i++;
}
}
}
以下是我所面临的问题的屏幕截图
任何人都可以帮我解决这个问题。
答案 0 :(得分:0)
您可以通过以下代码获取视角: -
CGFloat radians = atan2f(view.transform.b, view.transform.a);
CGFloat degrees = radians * (180 / M_PI);
您可以通过添加以下行来尝试一次: -
UIImageView.clipsToBounds为YES
它将有助于获得特定视图的弧度和旋转度。
希望它有效!