2016-04-28 1 views
1

На самом деле я хочу, чтобы преобразовать TOCropViewController делегата method.I используется bridge_header в быстром проекте & вызова TOCropViewController класс в bridge_header file.Then я поставил метод делегата в viewcontroller.swift.As далеко я сделал этоКак преобразовать метод делегата Objective-C TOCropViewController в Swift?

let cropViewController = TOCropViewController(image:image) 
cropViewController.delegate = self 
self.presentViewController(cropViewController, animated: true,  completion: nil) 
self.imageView.image = image 

Но хау может преобразовать ниже объектный метод делегата TOCropViewController в swift.

#pragma mark - Cropper Delegate - 


- (void)cropViewController:(TOCropViewController *)cropViewController didCropToImage:(UIImage *)image withRect:(CGRect)cropRect angle: (NSInteger)angle 
{ 
self.imageView.image = image; 
[self layoutImageView]; 

self.navigationItem.rightBarButtonItem.enabled = YES; 

CGRect viewFrame = [self.view convertRect:self.imageView.frame  toView:self.navigationController.view]; 
     self.imageView.hidden = YES; 
     [cropViewController dismissAnimatedFromParentViewController:self withCroppedImage:image toFrame:viewFrame completion:^{ 
    self.imageView.hidden = NO; 
}]; 
    } 

#pragma mark - Image Picker Delegate - 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo 
{ 
[self dismissViewControllerAnimated:YES completion:^{ 
    self.image = image; 
    TOCropViewController *cropController = [[TOCropViewController  alloc] initWithImage:image]; 
     cropController.delegate = self; 

     // Uncomment this to test out locked aspect ratio sizes 
     // cropController.defaultAspectRatio =  TOCropViewControllerAspectRatioSquare; 
     // cropController.aspectRatioLocked = YES; 

     // Uncomment this to place the toolbar at the top of the view controller 
     // cropController.toolbarPosition = TOCropViewControllerToolbarPositionTop; 

     [self presentViewController:cropController animated:YES completion:nil]; 
    }]; 
    } 

     - (void)imagePickerControllerDidCancel:(UIImagePickerController  *)picker 
    { 
    [self dismissViewControllerAnimated:YES completion:nil]; 
    } 

    #pragma mark - Gesture Recognizer - 
    - (void)didTapImageView 
    { 
    TOCropViewController *cropController = [[TOCropViewController alloc] initWithImage:self.image]; 
    cropController.delegate = self; 

    // Uncomment this to place the toolbar at the top of the view con troller 
     // cropController.toolbarPosition =  TOCropViewControllerToolbarPositionTop; 

     [self presentViewController:cropController animated:YES completion:nil]; 
     } 

Я ищу много на Google, но не нашел this..Some ссылку I поиск https://github.com/TimOliver/TOCropViewController/issues/25 & https://github.com/TimOliver/TOCropViewController/issues/71 ...

ответ

3
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) 
    { 
     self.dismissViewControllerAnimated(true, completion: {() -> Void in 
      if image != nil 
      { 
       let cropController:TOCropViewController = TOCropViewController(image: image) 
       cropController.delegate=self 
       self.presentViewController(cropController, animated: true, completion: nil) 
      } 
     }) 
    } 

    func imagePickerControllerDidCancel(picker: UIImagePickerController) 
    { 
     picker.dismissViewControllerAnimated(true, completion: {() -> Void in }) 
    } 

    // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 
    //  Cropper Delegate 
    // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 

    func cropViewController(cropViewController: TOCropViewController!, didCropToImage image: UIImage!, withRect cropRect: CGRect, angle: Int) 
    { 
     cropViewController.dismissViewControllerAnimated(true) {() -> Void in 
      self.imageView.image = image 
     } 
    } 

    func cropViewController(cropViewController: TOCropViewController!, didFinishCancelled cancelled: Bool) 
    { 
     cropViewController.dismissViewControllerAnimated(true) {() -> Void in } 
    } 
+0

Спасибо Jayesh .... Я буду использовать ваши быстрые методы. .... И полностью конвертируйте мой код в быстрый. –

+0

У меня была ошибка при попытке назначить делегата, просто чтобы прокомментировать, что все еще необходимо добавить TOCropViewControllerDelegate в объявление класса! –