2017-02-21 55 views
0

我正在拼贴应用程序和拼贴视图中我需要设置边框宽度和边框半径,视图将是另一个视图的底层和后视图会有背景颜色为棕色。我可以使用滑块更改边框宽度和角半径,但是在做完这些之后,我会在视图周围获得小的细小边框白线(如阴影)。我尝试使用阴影不透明度,工作。下面是我的代码。在应用边框时获取UIView上的白色边框宽度和边框颜色

- (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++; 
 
      
 
     } 
 
    } 
 

 
    
 
}

下面是这个问题的,我现在面临

This is the issue

谁能请帮助我在这个问题上的截图。

回答

0

您可以通过下面的代码得到的视角 - :

UIImageView.clipsToBounds为YES

它将帮助 -

CGFloat radians = atan2f(view.transform.b, view.transform.a); 
CGFloat degrees = radians * (180/M_PI); 

可以通过添加以下行一次尝试以获得特定视角的弧度和旋转角度。

希望它的作品!

+0

我不旋转那个view.that不是问题。当我使用棕色边框颜色时,我会在该视图周围看到一条白色的细线。请检查屏幕截图(问题标有红色箭头线)。 – Uttam