2017-01-28 3 views
0

J'utilise l'appareil photo ios par défaut dans mon application. Je voudrais changer quelque chose la vue d'édition qui montre après que l'utilisateur prenne une photo. Normalement, il montre un rectangle à recadrer, mais j'aimerais qu'il montre un cercle comment je ferais ceci.iOS: Comment rogner l'image par défaut de la caméra sur un cercle

+0

doublons possibles: https://stackoverflow.com/questions/28365819/ios-custom-uiimagepickercontroller-camera-crop-to -circle-in-preview-view et https://stackoverflow.com/questions/26160854/ios-custom-uiimagepickercontroller-camera-crop-to-circle-square-triangular-shape –

Répondre

0

Voici la solution qui pourrait vous aider à créer la superposition des cultures: -

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{ 
    if ([navigationController.viewControllers count] == 3) 
    { 
     CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height; 

     UIView *plCropOverlay = [[[viewController.view.subviews objectAtIndex:1]subviews] objectAtIndex:0]; 

     plCropOverlay.hidden = YES; 

     int position = 0; 

     if (screenHeight == 568) 
     { 
      position = 124; 
     } 
     else 
     { 
      position = 80; 
     } 

     CAShapeLayer *circleLayer = [CAShapeLayer layer]; 

     UIBezierPath *path2 = [UIBezierPath bezierPathWithOvalInRect: 
           CGRectMake(0.0f, position, 320.0f, 320.0f)]; 
     [path2 setUsesEvenOddFillRule:YES]; 

     [circleLayer setPath:[path2 CGPath]]; 

     [circleLayer setFillColor:[[UIColor clearColor] CGColor]]; 
     UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 320, screenHeight-72) cornerRadius:0]; 

     [path appendPath:path2]; 
     [path setUsesEvenOddFillRule:YES]; 

     CAShapeLayer *fillLayer = [CAShapeLayer layer]; 
     fillLayer.path = path.CGPath; 
     fillLayer.fillRule = kCAFillRuleEvenOdd; 
     fillLayer.fillColor = [UIColor blackColor].CGColor; 
     fillLayer.opacity = 0.8; 
     [viewController.view.layer addSublayer:fillLayer]; 

     UILabel *moveLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 320, 50)]; 
     [moveLabel setText:@"Move and Scale"]; 
     [moveLabel setTextAlignment:NSTextAlignmentCenter]; 
     [moveLabel setTextColor:[UIColor whiteColor]]; 

     [viewController.view addSubview:moveLabel]; 
    } 
} 
+0

Ce code rend l'appareil photo par défaut circulaire mais Je veux ouvrir la caméra par défaut et après cliquez sur l'image que je veux recadrer en forme circulaire. –