UIImagePicker allowsEditing stuck in center












35















I have a UIImagePicker that works perfect for a type of UIImagePickerControllerSourceTypePhotoLibrary, but when I use UIImagePickerControllerSourceTypeCamera, the editing box cannot move from the center of the image. So if the image is say taller than it is wide, the user cannot move the editing box to the top square of the image.



Anyone know why this would be the case? It only happens when the source is from the camera, not the library.



Edit: Some CODE!!!



if (actionSheet.tag == 2) {
if (buttonIndex == 0) { // Camera
// Check for camera
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES) {
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;

// Delegate is self
imagePicker.delegate = self;

// Show image picker
[self presentViewController:imagePicker
animated:YES
completion:^(void) {
}];
}
}
else if (buttonIndex == 1) { // Photo Library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] == YES) {
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = YES;

// Delegate is self
imagePicker.delegate = self;

// Show image picker
[self presentViewController:imagePicker
animated:YES


completion:^(void) {
}];
}
}


So as you can see, I display them the exact same, but the camera edit acts differently than the photo library edit.










share|improve this question





























    35















    I have a UIImagePicker that works perfect for a type of UIImagePickerControllerSourceTypePhotoLibrary, but when I use UIImagePickerControllerSourceTypeCamera, the editing box cannot move from the center of the image. So if the image is say taller than it is wide, the user cannot move the editing box to the top square of the image.



    Anyone know why this would be the case? It only happens when the source is from the camera, not the library.



    Edit: Some CODE!!!



    if (actionSheet.tag == 2) {
    if (buttonIndex == 0) { // Camera
    // Check for camera
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES) {
    // Create image picker controller
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    // Set source to the camera
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.allowsEditing = YES;

    // Delegate is self
    imagePicker.delegate = self;

    // Show image picker
    [self presentViewController:imagePicker
    animated:YES
    completion:^(void) {
    }];
    }
    }
    else if (buttonIndex == 1) { // Photo Library
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] == YES) {
    // Create image picker controller
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    // Set source to the camera
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.allowsEditing = YES;

    // Delegate is self
    imagePicker.delegate = self;

    // Show image picker
    [self presentViewController:imagePicker
    animated:YES


    completion:^(void) {
    }];
    }
    }


    So as you can see, I display them the exact same, but the camera edit acts differently than the photo library edit.










    share|improve this question



























      35












      35








      35


      10






      I have a UIImagePicker that works perfect for a type of UIImagePickerControllerSourceTypePhotoLibrary, but when I use UIImagePickerControllerSourceTypeCamera, the editing box cannot move from the center of the image. So if the image is say taller than it is wide, the user cannot move the editing box to the top square of the image.



      Anyone know why this would be the case? It only happens when the source is from the camera, not the library.



      Edit: Some CODE!!!



      if (actionSheet.tag == 2) {
      if (buttonIndex == 0) { // Camera
      // Check for camera
      if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES) {
      // Create image picker controller
      UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

      // Set source to the camera
      imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
      imagePicker.allowsEditing = YES;

      // Delegate is self
      imagePicker.delegate = self;

      // Show image picker
      [self presentViewController:imagePicker
      animated:YES
      completion:^(void) {
      }];
      }
      }
      else if (buttonIndex == 1) { // Photo Library
      if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] == YES) {
      // Create image picker controller
      UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

      // Set source to the camera
      imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
      imagePicker.allowsEditing = YES;

      // Delegate is self
      imagePicker.delegate = self;

      // Show image picker
      [self presentViewController:imagePicker
      animated:YES


      completion:^(void) {
      }];
      }
      }


      So as you can see, I display them the exact same, but the camera edit acts differently than the photo library edit.










      share|improve this question
















      I have a UIImagePicker that works perfect for a type of UIImagePickerControllerSourceTypePhotoLibrary, but when I use UIImagePickerControllerSourceTypeCamera, the editing box cannot move from the center of the image. So if the image is say taller than it is wide, the user cannot move the editing box to the top square of the image.



      Anyone know why this would be the case? It only happens when the source is from the camera, not the library.



      Edit: Some CODE!!!



      if (actionSheet.tag == 2) {
      if (buttonIndex == 0) { // Camera
      // Check for camera
      if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES) {
      // Create image picker controller
      UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

      // Set source to the camera
      imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
      imagePicker.allowsEditing = YES;

      // Delegate is self
      imagePicker.delegate = self;

      // Show image picker
      [self presentViewController:imagePicker
      animated:YES
      completion:^(void) {
      }];
      }
      }
      else if (buttonIndex == 1) { // Photo Library
      if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] == YES) {
      // Create image picker controller
      UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

      // Set source to the camera
      imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
      imagePicker.allowsEditing = YES;

      // Delegate is self
      imagePicker.delegate = self;

      // Show image picker
      [self presentViewController:imagePicker
      animated:YES


      completion:^(void) {
      }];
      }
      }


      So as you can see, I display them the exact same, but the camera edit acts differently than the photo library edit.







      iphone ios uiimagepickercontroller






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 28 '12 at 18:29







      Eric

















      asked Sep 27 '12 at 21:16









      EricEric

      4,54132441




      4,54132441
























          6 Answers
          6






          active

          oldest

          votes


















          48














          Looks like this behavior is just a bug in iOS 6... Basically you cannot move the editing box, it always bounces back to the middle unless you zoom in a bit. Hopefully they fix that soon.






          share|improve this answer



















          • 6





            I think this is still a bug in iOS 7

            – race_carr
            Jul 18 '14 at 16:17






          • 9





            aaaand still a bug in iOS 8. :(

            – Alex Ryan
            Aug 12 '14 at 22:36






          • 9





            Same bug exists in even iOS 8.1

            – Adnan
            Nov 4 '14 at 11:22






          • 5





            still strong in 8.2

            – Jkmn
            Mar 24 '15 at 17:19






          • 88





            I'm from the future, still a bug in iOS 12.0

            – Brent Dillingham
            Mar 28 '15 at 4:46



















          0














          This is the default behavior the Image Picker Controller, you can not change it. The only other option is to create your own cropping utility. Check out the link below for an example:



          https://github.com/ardalahmet/SSPhotoCropperViewController






          share|improve this answer



















          • 2





            But it works when you pick from an album.. Doesn't make sense. Why would you be able to move it more when its from an album rather than camera

            – Eric
            Sep 28 '12 at 4:24











          • @Eric you might have to post some code

            – Vikings
            Sep 28 '12 at 17:45











          • There is the code I use to display it

            – Eric
            Sep 28 '12 at 18:30











          • @Eric the editing box does not move at all, it is fixed in the middle of the screen, and you are able to scale the picture to fit in the box. Take a screenshot, because your code is right

            – Vikings
            Sep 28 '12 at 21:45






          • 1





            this isnt the default behaviour, i believe it is a bug in ios6. On previous ios versions it works fine, but on ios6 the image bounces back when you try and move it. However it does work slightly if you zoom in a bit.

            – Robert
            Oct 24 '12 at 22:44



















          0














          I know, this is not a good solution, but it works.



          I tested on iOS8+iPhone5, iOS9+iPhone6sPlus, iOS10+iPhone6, iOS10+iPhone6sPlus.



          CAUTION: PLImageScrollView and PLCropOverlayCropView are UNDOCUMENTED classes.



          - (void)showImagePickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType {
          UIImagePickerController *imagePickerController = [UIImagePickerController new];
          imagePickerController.sourceType = sourceType;
          imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
          imagePickerController.allowsEditing = YES;
          imagePickerController.delegate = self;
          [self presentViewController:imagePickerController animated:YES completion:^{
          [self fxxxImagePickerController:imagePickerController];
          }];
          }

          - (void)fxxxImagePickerController:(UIImagePickerController *)imagePickerController {
          if (!imagePickerController
          || !imagePickerController.allowsEditing
          || imagePickerController.sourceType != UIImagePickerControllerSourceTypeCamera) {
          return;
          }

          // !!!: UNDOCUMENTED CLASS
          Class ScrollViewClass = NSClassFromString(@"PLImageScrollView");
          Class CropViewClass = NSClassFromString(@"PLCropOverlayCropView");

          [imagePickerController.view eachSubview:^BOOL(UIView *subview, NSInteger depth) {
          if ([subview isKindOfClass:CropViewClass]) {
          // 0. crop rect position
          subview.frame = subview.superview.bounds;
          }
          else if ([subview isKindOfClass:[UIScrollView class]]
          && [subview isKindOfClass:ScrollViewClass]) {
          BOOL isNewImageScrollView = !self->_imageScrollView;
          self->_imageScrollView = (UIScrollView *)subview;
          // 1. enable scrolling
          CGSize size = self->_imageScrollView.frame.size;
          CGFloat inset = ABS(size.width - size.height) / 2;
          self->_imageScrollView.contentInset = UIEdgeInsetsMake(inset, 0, inset, 0);
          // 2. centering image by default
          if (isNewImageScrollView) {
          CGSize contentSize = self->_imageScrollView.contentSize;
          if (contentSize.height > contentSize.width) {
          CGFloat offset = round((contentSize.height - contentSize.width) / 2 - inset);
          self->_imageScrollView.contentOffset = CGPointMake(self->_imageScrollView.contentOffset.x, offset);
          }
          }
          }
          return YES;
          }];

          // prevent re-layout, maybe not necessary
          @weakify(self, imagePickerController);
          dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
          @strongify(self, imagePickerController);
          [self fxxxImagePickerController:imagePickerController];
          });
          }




          EDIT: The eachSubview: method traverses all the subviews tree.






          share|improve this answer































            0














            If you have set "View controller-based status bar appearance" to NO in info.plist and set status bar appearance as light using



             UIApplication.shared.statusBarStyle = .lightContent


            or using any other method , Then simply set the style as .default before presenting the image picker. for Eg:



            imagePicker.allowsEditing = true
            imagePicker.sourceType = .photoLibrary
            UIApplication.shared.statusBarStyle = .default
            present(imagePicker, animated: true, completion: nil)


            Change the source type according to your need either as photoLibrary or camera and in completion block of your didFinishPickingMediaWithInfo add the following to completion block.



            func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
            //let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

            var pickedImage : UIImage?
            if let img = info[UIImagePickerControllerEditedImage] as? UIImage
            {
            pickedImage = img

            }
            else if let img = info[UIImagePickerControllerOriginalImage] as? UIImage
            {
            pickedImage = img
            }
            dismiss(animated: true, completion: {
            UIApplication.shared.statusBarStyle = .lightContent
            })}


            Apparently this is a workaround for the same.Hope this helps.






            share|improve this answer































              0














              Stupid answer

              Reset contentInset of scrollview



              #import <objc/runtime.h>

              @interface WeakObjectContainer : NSObject
              @property (nonatomic, readonly, weak) id object;
              @end

              @implementation WeakObjectContainer
              - (instancetype) initWithObject:(id)object
              {
              if (!(self = [super init]))
              return nil;

              _object = object;

              return self;
              }
              @end

              @implementation UIImagePickerController (PLUS)

              // MARK: - Create a weak stored property in extension
              - (id)weakObjectForKey:(const void*)key {
              WeakObjectContainer *container = objc_getAssociatedObject(self, key);
              return [container object];
              }

              - (void)setWeakObject:(id)object forKey:(const void*)key {
              WeakObjectContainer *container = [[WeakObjectContainer alloc] initWithObject:object];
              objc_setAssociatedObject(self, key, container, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
              }

              // MARK: - Create a weak property for scrollView
              - (UIScrollView *)scrollView {
              return [self weakObjectForKey:_cmd];
              }

              - (void)setScrollView:(UIScrollView *)scrollView {
              [self setWeakObject:scrollView forKey:@selector(scrollView)];
              }

              // MARK: - Create a weak property for cropView
              - (UIView *)cropView {
              return [self weakObjectForKey:_cmd];
              }

              - (void)setCropView:(UIView *)cropView {
              [self setWeakObject:cropView forKey:@selector(cropView)];
              }

              // MARK: - Fix cannot move editing xox
              - (void)fixCannotMoveEditingBox {
              if (!self.scrollView || !self.cropView) {
              UIView *view = [self view];
              self.scrollView = [self findScrollView:view];
              self.cropView = [self findCropView:view];

              if (self.scrollView && self.cropView) {
              CGFloat top = self.cropView.frame.origin.y;
              CGFloat bottom = ({
              self.scrollView.frame.size.height - self.cropView.frame.size.height - self.cropView.frame.origin.y;
              });
              self.scrollView.contentInset = UIEdgeInsetsMake(top, 0, bottom, 0);
              self.scrollView.contentOffset = CGPointMake(0, -1);
              }
              }

              __weak typeof(self) weakself = self;
              dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC);
              dispatch_after(delay, dispatch_get_main_queue(), ^(void){
              __strong typeof(weakself) strongself = weakself;
              [strongself fixCannotMoveEditingBox];
              });
              }

              - (UIScrollView *)findScrollView:(UIView *)view {
              if ([view isKindOfClass:[UIScrollView class]]) {
              return (UIScrollView *)view;
              }
              for (UIView *subview in [view subviews]) {
              UIScrollView *view = [self findScrollView:subview];
              if (view) {
              return view;
              }
              }
              return nil;
              }

              - (UIView *)findCropView:(UIView *)view {
              CGFloat width = [[UIScreen mainScreen] bounds].size.width;
              CGSize size = [view frame].size;
              if (size.width == width && size.height == width) {
              return view;
              }
              for (UIView *subview in [view subviews]) {
              UIView *view = [self findCropView:subview];
              if (view) {
              return view;
              }
              }
              return nil;
              }

              @end


              then call it



              [imagePickerController fixCannotMoveEditingBox];





              share|improve this answer































                -1














                A workaround that solved it is to add an entry in info.plist with "View controller-based status bar appearance" set to NO






                share|improve this answer























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12630155%2fuiimagepicker-allowsediting-stuck-in-center%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  6 Answers
                  6






                  active

                  oldest

                  votes








                  6 Answers
                  6






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  48














                  Looks like this behavior is just a bug in iOS 6... Basically you cannot move the editing box, it always bounces back to the middle unless you zoom in a bit. Hopefully they fix that soon.






                  share|improve this answer



















                  • 6





                    I think this is still a bug in iOS 7

                    – race_carr
                    Jul 18 '14 at 16:17






                  • 9





                    aaaand still a bug in iOS 8. :(

                    – Alex Ryan
                    Aug 12 '14 at 22:36






                  • 9





                    Same bug exists in even iOS 8.1

                    – Adnan
                    Nov 4 '14 at 11:22






                  • 5





                    still strong in 8.2

                    – Jkmn
                    Mar 24 '15 at 17:19






                  • 88





                    I'm from the future, still a bug in iOS 12.0

                    – Brent Dillingham
                    Mar 28 '15 at 4:46
















                  48














                  Looks like this behavior is just a bug in iOS 6... Basically you cannot move the editing box, it always bounces back to the middle unless you zoom in a bit. Hopefully they fix that soon.






                  share|improve this answer



















                  • 6





                    I think this is still a bug in iOS 7

                    – race_carr
                    Jul 18 '14 at 16:17






                  • 9





                    aaaand still a bug in iOS 8. :(

                    – Alex Ryan
                    Aug 12 '14 at 22:36






                  • 9





                    Same bug exists in even iOS 8.1

                    – Adnan
                    Nov 4 '14 at 11:22






                  • 5





                    still strong in 8.2

                    – Jkmn
                    Mar 24 '15 at 17:19






                  • 88





                    I'm from the future, still a bug in iOS 12.0

                    – Brent Dillingham
                    Mar 28 '15 at 4:46














                  48












                  48








                  48







                  Looks like this behavior is just a bug in iOS 6... Basically you cannot move the editing box, it always bounces back to the middle unless you zoom in a bit. Hopefully they fix that soon.






                  share|improve this answer













                  Looks like this behavior is just a bug in iOS 6... Basically you cannot move the editing box, it always bounces back to the middle unless you zoom in a bit. Hopefully they fix that soon.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 31 '12 at 20:41









                  EricEric

                  4,54132441




                  4,54132441








                  • 6





                    I think this is still a bug in iOS 7

                    – race_carr
                    Jul 18 '14 at 16:17






                  • 9





                    aaaand still a bug in iOS 8. :(

                    – Alex Ryan
                    Aug 12 '14 at 22:36






                  • 9





                    Same bug exists in even iOS 8.1

                    – Adnan
                    Nov 4 '14 at 11:22






                  • 5





                    still strong in 8.2

                    – Jkmn
                    Mar 24 '15 at 17:19






                  • 88





                    I'm from the future, still a bug in iOS 12.0

                    – Brent Dillingham
                    Mar 28 '15 at 4:46














                  • 6





                    I think this is still a bug in iOS 7

                    – race_carr
                    Jul 18 '14 at 16:17






                  • 9





                    aaaand still a bug in iOS 8. :(

                    – Alex Ryan
                    Aug 12 '14 at 22:36






                  • 9





                    Same bug exists in even iOS 8.1

                    – Adnan
                    Nov 4 '14 at 11:22






                  • 5





                    still strong in 8.2

                    – Jkmn
                    Mar 24 '15 at 17:19






                  • 88





                    I'm from the future, still a bug in iOS 12.0

                    – Brent Dillingham
                    Mar 28 '15 at 4:46








                  6




                  6





                  I think this is still a bug in iOS 7

                  – race_carr
                  Jul 18 '14 at 16:17





                  I think this is still a bug in iOS 7

                  – race_carr
                  Jul 18 '14 at 16:17




                  9




                  9





                  aaaand still a bug in iOS 8. :(

                  – Alex Ryan
                  Aug 12 '14 at 22:36





                  aaaand still a bug in iOS 8. :(

                  – Alex Ryan
                  Aug 12 '14 at 22:36




                  9




                  9





                  Same bug exists in even iOS 8.1

                  – Adnan
                  Nov 4 '14 at 11:22





                  Same bug exists in even iOS 8.1

                  – Adnan
                  Nov 4 '14 at 11:22




                  5




                  5





                  still strong in 8.2

                  – Jkmn
                  Mar 24 '15 at 17:19





                  still strong in 8.2

                  – Jkmn
                  Mar 24 '15 at 17:19




                  88




                  88





                  I'm from the future, still a bug in iOS 12.0

                  – Brent Dillingham
                  Mar 28 '15 at 4:46





                  I'm from the future, still a bug in iOS 12.0

                  – Brent Dillingham
                  Mar 28 '15 at 4:46













                  0














                  This is the default behavior the Image Picker Controller, you can not change it. The only other option is to create your own cropping utility. Check out the link below for an example:



                  https://github.com/ardalahmet/SSPhotoCropperViewController






                  share|improve this answer



















                  • 2





                    But it works when you pick from an album.. Doesn't make sense. Why would you be able to move it more when its from an album rather than camera

                    – Eric
                    Sep 28 '12 at 4:24











                  • @Eric you might have to post some code

                    – Vikings
                    Sep 28 '12 at 17:45











                  • There is the code I use to display it

                    – Eric
                    Sep 28 '12 at 18:30











                  • @Eric the editing box does not move at all, it is fixed in the middle of the screen, and you are able to scale the picture to fit in the box. Take a screenshot, because your code is right

                    – Vikings
                    Sep 28 '12 at 21:45






                  • 1





                    this isnt the default behaviour, i believe it is a bug in ios6. On previous ios versions it works fine, but on ios6 the image bounces back when you try and move it. However it does work slightly if you zoom in a bit.

                    – Robert
                    Oct 24 '12 at 22:44
















                  0














                  This is the default behavior the Image Picker Controller, you can not change it. The only other option is to create your own cropping utility. Check out the link below for an example:



                  https://github.com/ardalahmet/SSPhotoCropperViewController






                  share|improve this answer



















                  • 2





                    But it works when you pick from an album.. Doesn't make sense. Why would you be able to move it more when its from an album rather than camera

                    – Eric
                    Sep 28 '12 at 4:24











                  • @Eric you might have to post some code

                    – Vikings
                    Sep 28 '12 at 17:45











                  • There is the code I use to display it

                    – Eric
                    Sep 28 '12 at 18:30











                  • @Eric the editing box does not move at all, it is fixed in the middle of the screen, and you are able to scale the picture to fit in the box. Take a screenshot, because your code is right

                    – Vikings
                    Sep 28 '12 at 21:45






                  • 1





                    this isnt the default behaviour, i believe it is a bug in ios6. On previous ios versions it works fine, but on ios6 the image bounces back when you try and move it. However it does work slightly if you zoom in a bit.

                    – Robert
                    Oct 24 '12 at 22:44














                  0












                  0








                  0







                  This is the default behavior the Image Picker Controller, you can not change it. The only other option is to create your own cropping utility. Check out the link below for an example:



                  https://github.com/ardalahmet/SSPhotoCropperViewController






                  share|improve this answer













                  This is the default behavior the Image Picker Controller, you can not change it. The only other option is to create your own cropping utility. Check out the link below for an example:



                  https://github.com/ardalahmet/SSPhotoCropperViewController







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 27 '12 at 22:08









                  VikingsVikings

                  1,8122845




                  1,8122845








                  • 2





                    But it works when you pick from an album.. Doesn't make sense. Why would you be able to move it more when its from an album rather than camera

                    – Eric
                    Sep 28 '12 at 4:24











                  • @Eric you might have to post some code

                    – Vikings
                    Sep 28 '12 at 17:45











                  • There is the code I use to display it

                    – Eric
                    Sep 28 '12 at 18:30











                  • @Eric the editing box does not move at all, it is fixed in the middle of the screen, and you are able to scale the picture to fit in the box. Take a screenshot, because your code is right

                    – Vikings
                    Sep 28 '12 at 21:45






                  • 1





                    this isnt the default behaviour, i believe it is a bug in ios6. On previous ios versions it works fine, but on ios6 the image bounces back when you try and move it. However it does work slightly if you zoom in a bit.

                    – Robert
                    Oct 24 '12 at 22:44














                  • 2





                    But it works when you pick from an album.. Doesn't make sense. Why would you be able to move it more when its from an album rather than camera

                    – Eric
                    Sep 28 '12 at 4:24











                  • @Eric you might have to post some code

                    – Vikings
                    Sep 28 '12 at 17:45











                  • There is the code I use to display it

                    – Eric
                    Sep 28 '12 at 18:30











                  • @Eric the editing box does not move at all, it is fixed in the middle of the screen, and you are able to scale the picture to fit in the box. Take a screenshot, because your code is right

                    – Vikings
                    Sep 28 '12 at 21:45






                  • 1





                    this isnt the default behaviour, i believe it is a bug in ios6. On previous ios versions it works fine, but on ios6 the image bounces back when you try and move it. However it does work slightly if you zoom in a bit.

                    – Robert
                    Oct 24 '12 at 22:44








                  2




                  2





                  But it works when you pick from an album.. Doesn't make sense. Why would you be able to move it more when its from an album rather than camera

                  – Eric
                  Sep 28 '12 at 4:24





                  But it works when you pick from an album.. Doesn't make sense. Why would you be able to move it more when its from an album rather than camera

                  – Eric
                  Sep 28 '12 at 4:24













                  @Eric you might have to post some code

                  – Vikings
                  Sep 28 '12 at 17:45





                  @Eric you might have to post some code

                  – Vikings
                  Sep 28 '12 at 17:45













                  There is the code I use to display it

                  – Eric
                  Sep 28 '12 at 18:30





                  There is the code I use to display it

                  – Eric
                  Sep 28 '12 at 18:30













                  @Eric the editing box does not move at all, it is fixed in the middle of the screen, and you are able to scale the picture to fit in the box. Take a screenshot, because your code is right

                  – Vikings
                  Sep 28 '12 at 21:45





                  @Eric the editing box does not move at all, it is fixed in the middle of the screen, and you are able to scale the picture to fit in the box. Take a screenshot, because your code is right

                  – Vikings
                  Sep 28 '12 at 21:45




                  1




                  1





                  this isnt the default behaviour, i believe it is a bug in ios6. On previous ios versions it works fine, but on ios6 the image bounces back when you try and move it. However it does work slightly if you zoom in a bit.

                  – Robert
                  Oct 24 '12 at 22:44





                  this isnt the default behaviour, i believe it is a bug in ios6. On previous ios versions it works fine, but on ios6 the image bounces back when you try and move it. However it does work slightly if you zoom in a bit.

                  – Robert
                  Oct 24 '12 at 22:44











                  0














                  I know, this is not a good solution, but it works.



                  I tested on iOS8+iPhone5, iOS9+iPhone6sPlus, iOS10+iPhone6, iOS10+iPhone6sPlus.



                  CAUTION: PLImageScrollView and PLCropOverlayCropView are UNDOCUMENTED classes.



                  - (void)showImagePickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType {
                  UIImagePickerController *imagePickerController = [UIImagePickerController new];
                  imagePickerController.sourceType = sourceType;
                  imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
                  imagePickerController.allowsEditing = YES;
                  imagePickerController.delegate = self;
                  [self presentViewController:imagePickerController animated:YES completion:^{
                  [self fxxxImagePickerController:imagePickerController];
                  }];
                  }

                  - (void)fxxxImagePickerController:(UIImagePickerController *)imagePickerController {
                  if (!imagePickerController
                  || !imagePickerController.allowsEditing
                  || imagePickerController.sourceType != UIImagePickerControllerSourceTypeCamera) {
                  return;
                  }

                  // !!!: UNDOCUMENTED CLASS
                  Class ScrollViewClass = NSClassFromString(@"PLImageScrollView");
                  Class CropViewClass = NSClassFromString(@"PLCropOverlayCropView");

                  [imagePickerController.view eachSubview:^BOOL(UIView *subview, NSInteger depth) {
                  if ([subview isKindOfClass:CropViewClass]) {
                  // 0. crop rect position
                  subview.frame = subview.superview.bounds;
                  }
                  else if ([subview isKindOfClass:[UIScrollView class]]
                  && [subview isKindOfClass:ScrollViewClass]) {
                  BOOL isNewImageScrollView = !self->_imageScrollView;
                  self->_imageScrollView = (UIScrollView *)subview;
                  // 1. enable scrolling
                  CGSize size = self->_imageScrollView.frame.size;
                  CGFloat inset = ABS(size.width - size.height) / 2;
                  self->_imageScrollView.contentInset = UIEdgeInsetsMake(inset, 0, inset, 0);
                  // 2. centering image by default
                  if (isNewImageScrollView) {
                  CGSize contentSize = self->_imageScrollView.contentSize;
                  if (contentSize.height > contentSize.width) {
                  CGFloat offset = round((contentSize.height - contentSize.width) / 2 - inset);
                  self->_imageScrollView.contentOffset = CGPointMake(self->_imageScrollView.contentOffset.x, offset);
                  }
                  }
                  }
                  return YES;
                  }];

                  // prevent re-layout, maybe not necessary
                  @weakify(self, imagePickerController);
                  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                  @strongify(self, imagePickerController);
                  [self fxxxImagePickerController:imagePickerController];
                  });
                  }




                  EDIT: The eachSubview: method traverses all the subviews tree.






                  share|improve this answer




























                    0














                    I know, this is not a good solution, but it works.



                    I tested on iOS8+iPhone5, iOS9+iPhone6sPlus, iOS10+iPhone6, iOS10+iPhone6sPlus.



                    CAUTION: PLImageScrollView and PLCropOverlayCropView are UNDOCUMENTED classes.



                    - (void)showImagePickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType {
                    UIImagePickerController *imagePickerController = [UIImagePickerController new];
                    imagePickerController.sourceType = sourceType;
                    imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
                    imagePickerController.allowsEditing = YES;
                    imagePickerController.delegate = self;
                    [self presentViewController:imagePickerController animated:YES completion:^{
                    [self fxxxImagePickerController:imagePickerController];
                    }];
                    }

                    - (void)fxxxImagePickerController:(UIImagePickerController *)imagePickerController {
                    if (!imagePickerController
                    || !imagePickerController.allowsEditing
                    || imagePickerController.sourceType != UIImagePickerControllerSourceTypeCamera) {
                    return;
                    }

                    // !!!: UNDOCUMENTED CLASS
                    Class ScrollViewClass = NSClassFromString(@"PLImageScrollView");
                    Class CropViewClass = NSClassFromString(@"PLCropOverlayCropView");

                    [imagePickerController.view eachSubview:^BOOL(UIView *subview, NSInteger depth) {
                    if ([subview isKindOfClass:CropViewClass]) {
                    // 0. crop rect position
                    subview.frame = subview.superview.bounds;
                    }
                    else if ([subview isKindOfClass:[UIScrollView class]]
                    && [subview isKindOfClass:ScrollViewClass]) {
                    BOOL isNewImageScrollView = !self->_imageScrollView;
                    self->_imageScrollView = (UIScrollView *)subview;
                    // 1. enable scrolling
                    CGSize size = self->_imageScrollView.frame.size;
                    CGFloat inset = ABS(size.width - size.height) / 2;
                    self->_imageScrollView.contentInset = UIEdgeInsetsMake(inset, 0, inset, 0);
                    // 2. centering image by default
                    if (isNewImageScrollView) {
                    CGSize contentSize = self->_imageScrollView.contentSize;
                    if (contentSize.height > contentSize.width) {
                    CGFloat offset = round((contentSize.height - contentSize.width) / 2 - inset);
                    self->_imageScrollView.contentOffset = CGPointMake(self->_imageScrollView.contentOffset.x, offset);
                    }
                    }
                    }
                    return YES;
                    }];

                    // prevent re-layout, maybe not necessary
                    @weakify(self, imagePickerController);
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    @strongify(self, imagePickerController);
                    [self fxxxImagePickerController:imagePickerController];
                    });
                    }




                    EDIT: The eachSubview: method traverses all the subviews tree.






                    share|improve this answer


























                      0












                      0








                      0







                      I know, this is not a good solution, but it works.



                      I tested on iOS8+iPhone5, iOS9+iPhone6sPlus, iOS10+iPhone6, iOS10+iPhone6sPlus.



                      CAUTION: PLImageScrollView and PLCropOverlayCropView are UNDOCUMENTED classes.



                      - (void)showImagePickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType {
                      UIImagePickerController *imagePickerController = [UIImagePickerController new];
                      imagePickerController.sourceType = sourceType;
                      imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
                      imagePickerController.allowsEditing = YES;
                      imagePickerController.delegate = self;
                      [self presentViewController:imagePickerController animated:YES completion:^{
                      [self fxxxImagePickerController:imagePickerController];
                      }];
                      }

                      - (void)fxxxImagePickerController:(UIImagePickerController *)imagePickerController {
                      if (!imagePickerController
                      || !imagePickerController.allowsEditing
                      || imagePickerController.sourceType != UIImagePickerControllerSourceTypeCamera) {
                      return;
                      }

                      // !!!: UNDOCUMENTED CLASS
                      Class ScrollViewClass = NSClassFromString(@"PLImageScrollView");
                      Class CropViewClass = NSClassFromString(@"PLCropOverlayCropView");

                      [imagePickerController.view eachSubview:^BOOL(UIView *subview, NSInteger depth) {
                      if ([subview isKindOfClass:CropViewClass]) {
                      // 0. crop rect position
                      subview.frame = subview.superview.bounds;
                      }
                      else if ([subview isKindOfClass:[UIScrollView class]]
                      && [subview isKindOfClass:ScrollViewClass]) {
                      BOOL isNewImageScrollView = !self->_imageScrollView;
                      self->_imageScrollView = (UIScrollView *)subview;
                      // 1. enable scrolling
                      CGSize size = self->_imageScrollView.frame.size;
                      CGFloat inset = ABS(size.width - size.height) / 2;
                      self->_imageScrollView.contentInset = UIEdgeInsetsMake(inset, 0, inset, 0);
                      // 2. centering image by default
                      if (isNewImageScrollView) {
                      CGSize contentSize = self->_imageScrollView.contentSize;
                      if (contentSize.height > contentSize.width) {
                      CGFloat offset = round((contentSize.height - contentSize.width) / 2 - inset);
                      self->_imageScrollView.contentOffset = CGPointMake(self->_imageScrollView.contentOffset.x, offset);
                      }
                      }
                      }
                      return YES;
                      }];

                      // prevent re-layout, maybe not necessary
                      @weakify(self, imagePickerController);
                      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                      @strongify(self, imagePickerController);
                      [self fxxxImagePickerController:imagePickerController];
                      });
                      }




                      EDIT: The eachSubview: method traverses all the subviews tree.






                      share|improve this answer













                      I know, this is not a good solution, but it works.



                      I tested on iOS8+iPhone5, iOS9+iPhone6sPlus, iOS10+iPhone6, iOS10+iPhone6sPlus.



                      CAUTION: PLImageScrollView and PLCropOverlayCropView are UNDOCUMENTED classes.



                      - (void)showImagePickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType {
                      UIImagePickerController *imagePickerController = [UIImagePickerController new];
                      imagePickerController.sourceType = sourceType;
                      imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
                      imagePickerController.allowsEditing = YES;
                      imagePickerController.delegate = self;
                      [self presentViewController:imagePickerController animated:YES completion:^{
                      [self fxxxImagePickerController:imagePickerController];
                      }];
                      }

                      - (void)fxxxImagePickerController:(UIImagePickerController *)imagePickerController {
                      if (!imagePickerController
                      || !imagePickerController.allowsEditing
                      || imagePickerController.sourceType != UIImagePickerControllerSourceTypeCamera) {
                      return;
                      }

                      // !!!: UNDOCUMENTED CLASS
                      Class ScrollViewClass = NSClassFromString(@"PLImageScrollView");
                      Class CropViewClass = NSClassFromString(@"PLCropOverlayCropView");

                      [imagePickerController.view eachSubview:^BOOL(UIView *subview, NSInteger depth) {
                      if ([subview isKindOfClass:CropViewClass]) {
                      // 0. crop rect position
                      subview.frame = subview.superview.bounds;
                      }
                      else if ([subview isKindOfClass:[UIScrollView class]]
                      && [subview isKindOfClass:ScrollViewClass]) {
                      BOOL isNewImageScrollView = !self->_imageScrollView;
                      self->_imageScrollView = (UIScrollView *)subview;
                      // 1. enable scrolling
                      CGSize size = self->_imageScrollView.frame.size;
                      CGFloat inset = ABS(size.width - size.height) / 2;
                      self->_imageScrollView.contentInset = UIEdgeInsetsMake(inset, 0, inset, 0);
                      // 2. centering image by default
                      if (isNewImageScrollView) {
                      CGSize contentSize = self->_imageScrollView.contentSize;
                      if (contentSize.height > contentSize.width) {
                      CGFloat offset = round((contentSize.height - contentSize.width) / 2 - inset);
                      self->_imageScrollView.contentOffset = CGPointMake(self->_imageScrollView.contentOffset.x, offset);
                      }
                      }
                      }
                      return YES;
                      }];

                      // prevent re-layout, maybe not necessary
                      @weakify(self, imagePickerController);
                      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                      @strongify(self, imagePickerController);
                      [self fxxxImagePickerController:imagePickerController];
                      });
                      }




                      EDIT: The eachSubview: method traverses all the subviews tree.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 1 '16 at 6:57









                      iwilliwill

                      1,41942141




                      1,41942141























                          0














                          If you have set "View controller-based status bar appearance" to NO in info.plist and set status bar appearance as light using



                           UIApplication.shared.statusBarStyle = .lightContent


                          or using any other method , Then simply set the style as .default before presenting the image picker. for Eg:



                          imagePicker.allowsEditing = true
                          imagePicker.sourceType = .photoLibrary
                          UIApplication.shared.statusBarStyle = .default
                          present(imagePicker, animated: true, completion: nil)


                          Change the source type according to your need either as photoLibrary or camera and in completion block of your didFinishPickingMediaWithInfo add the following to completion block.



                          func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
                          //let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

                          var pickedImage : UIImage?
                          if let img = info[UIImagePickerControllerEditedImage] as? UIImage
                          {
                          pickedImage = img

                          }
                          else if let img = info[UIImagePickerControllerOriginalImage] as? UIImage
                          {
                          pickedImage = img
                          }
                          dismiss(animated: true, completion: {
                          UIApplication.shared.statusBarStyle = .lightContent
                          })}


                          Apparently this is a workaround for the same.Hope this helps.






                          share|improve this answer




























                            0














                            If you have set "View controller-based status bar appearance" to NO in info.plist and set status bar appearance as light using



                             UIApplication.shared.statusBarStyle = .lightContent


                            or using any other method , Then simply set the style as .default before presenting the image picker. for Eg:



                            imagePicker.allowsEditing = true
                            imagePicker.sourceType = .photoLibrary
                            UIApplication.shared.statusBarStyle = .default
                            present(imagePicker, animated: true, completion: nil)


                            Change the source type according to your need either as photoLibrary or camera and in completion block of your didFinishPickingMediaWithInfo add the following to completion block.



                            func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
                            //let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

                            var pickedImage : UIImage?
                            if let img = info[UIImagePickerControllerEditedImage] as? UIImage
                            {
                            pickedImage = img

                            }
                            else if let img = info[UIImagePickerControllerOriginalImage] as? UIImage
                            {
                            pickedImage = img
                            }
                            dismiss(animated: true, completion: {
                            UIApplication.shared.statusBarStyle = .lightContent
                            })}


                            Apparently this is a workaround for the same.Hope this helps.






                            share|improve this answer


























                              0












                              0








                              0







                              If you have set "View controller-based status bar appearance" to NO in info.plist and set status bar appearance as light using



                               UIApplication.shared.statusBarStyle = .lightContent


                              or using any other method , Then simply set the style as .default before presenting the image picker. for Eg:



                              imagePicker.allowsEditing = true
                              imagePicker.sourceType = .photoLibrary
                              UIApplication.shared.statusBarStyle = .default
                              present(imagePicker, animated: true, completion: nil)


                              Change the source type according to your need either as photoLibrary or camera and in completion block of your didFinishPickingMediaWithInfo add the following to completion block.



                              func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
                              //let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

                              var pickedImage : UIImage?
                              if let img = info[UIImagePickerControllerEditedImage] as? UIImage
                              {
                              pickedImage = img

                              }
                              else if let img = info[UIImagePickerControllerOriginalImage] as? UIImage
                              {
                              pickedImage = img
                              }
                              dismiss(animated: true, completion: {
                              UIApplication.shared.statusBarStyle = .lightContent
                              })}


                              Apparently this is a workaround for the same.Hope this helps.






                              share|improve this answer













                              If you have set "View controller-based status bar appearance" to NO in info.plist and set status bar appearance as light using



                               UIApplication.shared.statusBarStyle = .lightContent


                              or using any other method , Then simply set the style as .default before presenting the image picker. for Eg:



                              imagePicker.allowsEditing = true
                              imagePicker.sourceType = .photoLibrary
                              UIApplication.shared.statusBarStyle = .default
                              present(imagePicker, animated: true, completion: nil)


                              Change the source type according to your need either as photoLibrary or camera and in completion block of your didFinishPickingMediaWithInfo add the following to completion block.



                              func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
                              //let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

                              var pickedImage : UIImage?
                              if let img = info[UIImagePickerControllerEditedImage] as? UIImage
                              {
                              pickedImage = img

                              }
                              else if let img = info[UIImagePickerControllerOriginalImage] as? UIImage
                              {
                              pickedImage = img
                              }
                              dismiss(animated: true, completion: {
                              UIApplication.shared.statusBarStyle = .lightContent
                              })}


                              Apparently this is a workaround for the same.Hope this helps.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Aug 20 '18 at 8:13









                              ashin asokashin asok

                              78211




                              78211























                                  0














                                  Stupid answer

                                  Reset contentInset of scrollview



                                  #import <objc/runtime.h>

                                  @interface WeakObjectContainer : NSObject
                                  @property (nonatomic, readonly, weak) id object;
                                  @end

                                  @implementation WeakObjectContainer
                                  - (instancetype) initWithObject:(id)object
                                  {
                                  if (!(self = [super init]))
                                  return nil;

                                  _object = object;

                                  return self;
                                  }
                                  @end

                                  @implementation UIImagePickerController (PLUS)

                                  // MARK: - Create a weak stored property in extension
                                  - (id)weakObjectForKey:(const void*)key {
                                  WeakObjectContainer *container = objc_getAssociatedObject(self, key);
                                  return [container object];
                                  }

                                  - (void)setWeakObject:(id)object forKey:(const void*)key {
                                  WeakObjectContainer *container = [[WeakObjectContainer alloc] initWithObject:object];
                                  objc_setAssociatedObject(self, key, container, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
                                  }

                                  // MARK: - Create a weak property for scrollView
                                  - (UIScrollView *)scrollView {
                                  return [self weakObjectForKey:_cmd];
                                  }

                                  - (void)setScrollView:(UIScrollView *)scrollView {
                                  [self setWeakObject:scrollView forKey:@selector(scrollView)];
                                  }

                                  // MARK: - Create a weak property for cropView
                                  - (UIView *)cropView {
                                  return [self weakObjectForKey:_cmd];
                                  }

                                  - (void)setCropView:(UIView *)cropView {
                                  [self setWeakObject:cropView forKey:@selector(cropView)];
                                  }

                                  // MARK: - Fix cannot move editing xox
                                  - (void)fixCannotMoveEditingBox {
                                  if (!self.scrollView || !self.cropView) {
                                  UIView *view = [self view];
                                  self.scrollView = [self findScrollView:view];
                                  self.cropView = [self findCropView:view];

                                  if (self.scrollView && self.cropView) {
                                  CGFloat top = self.cropView.frame.origin.y;
                                  CGFloat bottom = ({
                                  self.scrollView.frame.size.height - self.cropView.frame.size.height - self.cropView.frame.origin.y;
                                  });
                                  self.scrollView.contentInset = UIEdgeInsetsMake(top, 0, bottom, 0);
                                  self.scrollView.contentOffset = CGPointMake(0, -1);
                                  }
                                  }

                                  __weak typeof(self) weakself = self;
                                  dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC);
                                  dispatch_after(delay, dispatch_get_main_queue(), ^(void){
                                  __strong typeof(weakself) strongself = weakself;
                                  [strongself fixCannotMoveEditingBox];
                                  });
                                  }

                                  - (UIScrollView *)findScrollView:(UIView *)view {
                                  if ([view isKindOfClass:[UIScrollView class]]) {
                                  return (UIScrollView *)view;
                                  }
                                  for (UIView *subview in [view subviews]) {
                                  UIScrollView *view = [self findScrollView:subview];
                                  if (view) {
                                  return view;
                                  }
                                  }
                                  return nil;
                                  }

                                  - (UIView *)findCropView:(UIView *)view {
                                  CGFloat width = [[UIScreen mainScreen] bounds].size.width;
                                  CGSize size = [view frame].size;
                                  if (size.width == width && size.height == width) {
                                  return view;
                                  }
                                  for (UIView *subview in [view subviews]) {
                                  UIView *view = [self findCropView:subview];
                                  if (view) {
                                  return view;
                                  }
                                  }
                                  return nil;
                                  }

                                  @end


                                  then call it



                                  [imagePickerController fixCannotMoveEditingBox];





                                  share|improve this answer




























                                    0














                                    Stupid answer

                                    Reset contentInset of scrollview



                                    #import <objc/runtime.h>

                                    @interface WeakObjectContainer : NSObject
                                    @property (nonatomic, readonly, weak) id object;
                                    @end

                                    @implementation WeakObjectContainer
                                    - (instancetype) initWithObject:(id)object
                                    {
                                    if (!(self = [super init]))
                                    return nil;

                                    _object = object;

                                    return self;
                                    }
                                    @end

                                    @implementation UIImagePickerController (PLUS)

                                    // MARK: - Create a weak stored property in extension
                                    - (id)weakObjectForKey:(const void*)key {
                                    WeakObjectContainer *container = objc_getAssociatedObject(self, key);
                                    return [container object];
                                    }

                                    - (void)setWeakObject:(id)object forKey:(const void*)key {
                                    WeakObjectContainer *container = [[WeakObjectContainer alloc] initWithObject:object];
                                    objc_setAssociatedObject(self, key, container, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
                                    }

                                    // MARK: - Create a weak property for scrollView
                                    - (UIScrollView *)scrollView {
                                    return [self weakObjectForKey:_cmd];
                                    }

                                    - (void)setScrollView:(UIScrollView *)scrollView {
                                    [self setWeakObject:scrollView forKey:@selector(scrollView)];
                                    }

                                    // MARK: - Create a weak property for cropView
                                    - (UIView *)cropView {
                                    return [self weakObjectForKey:_cmd];
                                    }

                                    - (void)setCropView:(UIView *)cropView {
                                    [self setWeakObject:cropView forKey:@selector(cropView)];
                                    }

                                    // MARK: - Fix cannot move editing xox
                                    - (void)fixCannotMoveEditingBox {
                                    if (!self.scrollView || !self.cropView) {
                                    UIView *view = [self view];
                                    self.scrollView = [self findScrollView:view];
                                    self.cropView = [self findCropView:view];

                                    if (self.scrollView && self.cropView) {
                                    CGFloat top = self.cropView.frame.origin.y;
                                    CGFloat bottom = ({
                                    self.scrollView.frame.size.height - self.cropView.frame.size.height - self.cropView.frame.origin.y;
                                    });
                                    self.scrollView.contentInset = UIEdgeInsetsMake(top, 0, bottom, 0);
                                    self.scrollView.contentOffset = CGPointMake(0, -1);
                                    }
                                    }

                                    __weak typeof(self) weakself = self;
                                    dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC);
                                    dispatch_after(delay, dispatch_get_main_queue(), ^(void){
                                    __strong typeof(weakself) strongself = weakself;
                                    [strongself fixCannotMoveEditingBox];
                                    });
                                    }

                                    - (UIScrollView *)findScrollView:(UIView *)view {
                                    if ([view isKindOfClass:[UIScrollView class]]) {
                                    return (UIScrollView *)view;
                                    }
                                    for (UIView *subview in [view subviews]) {
                                    UIScrollView *view = [self findScrollView:subview];
                                    if (view) {
                                    return view;
                                    }
                                    }
                                    return nil;
                                    }

                                    - (UIView *)findCropView:(UIView *)view {
                                    CGFloat width = [[UIScreen mainScreen] bounds].size.width;
                                    CGSize size = [view frame].size;
                                    if (size.width == width && size.height == width) {
                                    return view;
                                    }
                                    for (UIView *subview in [view subviews]) {
                                    UIView *view = [self findCropView:subview];
                                    if (view) {
                                    return view;
                                    }
                                    }
                                    return nil;
                                    }

                                    @end


                                    then call it



                                    [imagePickerController fixCannotMoveEditingBox];





                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      Stupid answer

                                      Reset contentInset of scrollview



                                      #import <objc/runtime.h>

                                      @interface WeakObjectContainer : NSObject
                                      @property (nonatomic, readonly, weak) id object;
                                      @end

                                      @implementation WeakObjectContainer
                                      - (instancetype) initWithObject:(id)object
                                      {
                                      if (!(self = [super init]))
                                      return nil;

                                      _object = object;

                                      return self;
                                      }
                                      @end

                                      @implementation UIImagePickerController (PLUS)

                                      // MARK: - Create a weak stored property in extension
                                      - (id)weakObjectForKey:(const void*)key {
                                      WeakObjectContainer *container = objc_getAssociatedObject(self, key);
                                      return [container object];
                                      }

                                      - (void)setWeakObject:(id)object forKey:(const void*)key {
                                      WeakObjectContainer *container = [[WeakObjectContainer alloc] initWithObject:object];
                                      objc_setAssociatedObject(self, key, container, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
                                      }

                                      // MARK: - Create a weak property for scrollView
                                      - (UIScrollView *)scrollView {
                                      return [self weakObjectForKey:_cmd];
                                      }

                                      - (void)setScrollView:(UIScrollView *)scrollView {
                                      [self setWeakObject:scrollView forKey:@selector(scrollView)];
                                      }

                                      // MARK: - Create a weak property for cropView
                                      - (UIView *)cropView {
                                      return [self weakObjectForKey:_cmd];
                                      }

                                      - (void)setCropView:(UIView *)cropView {
                                      [self setWeakObject:cropView forKey:@selector(cropView)];
                                      }

                                      // MARK: - Fix cannot move editing xox
                                      - (void)fixCannotMoveEditingBox {
                                      if (!self.scrollView || !self.cropView) {
                                      UIView *view = [self view];
                                      self.scrollView = [self findScrollView:view];
                                      self.cropView = [self findCropView:view];

                                      if (self.scrollView && self.cropView) {
                                      CGFloat top = self.cropView.frame.origin.y;
                                      CGFloat bottom = ({
                                      self.scrollView.frame.size.height - self.cropView.frame.size.height - self.cropView.frame.origin.y;
                                      });
                                      self.scrollView.contentInset = UIEdgeInsetsMake(top, 0, bottom, 0);
                                      self.scrollView.contentOffset = CGPointMake(0, -1);
                                      }
                                      }

                                      __weak typeof(self) weakself = self;
                                      dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC);
                                      dispatch_after(delay, dispatch_get_main_queue(), ^(void){
                                      __strong typeof(weakself) strongself = weakself;
                                      [strongself fixCannotMoveEditingBox];
                                      });
                                      }

                                      - (UIScrollView *)findScrollView:(UIView *)view {
                                      if ([view isKindOfClass:[UIScrollView class]]) {
                                      return (UIScrollView *)view;
                                      }
                                      for (UIView *subview in [view subviews]) {
                                      UIScrollView *view = [self findScrollView:subview];
                                      if (view) {
                                      return view;
                                      }
                                      }
                                      return nil;
                                      }

                                      - (UIView *)findCropView:(UIView *)view {
                                      CGFloat width = [[UIScreen mainScreen] bounds].size.width;
                                      CGSize size = [view frame].size;
                                      if (size.width == width && size.height == width) {
                                      return view;
                                      }
                                      for (UIView *subview in [view subviews]) {
                                      UIView *view = [self findCropView:subview];
                                      if (view) {
                                      return view;
                                      }
                                      }
                                      return nil;
                                      }

                                      @end


                                      then call it



                                      [imagePickerController fixCannotMoveEditingBox];





                                      share|improve this answer













                                      Stupid answer

                                      Reset contentInset of scrollview



                                      #import <objc/runtime.h>

                                      @interface WeakObjectContainer : NSObject
                                      @property (nonatomic, readonly, weak) id object;
                                      @end

                                      @implementation WeakObjectContainer
                                      - (instancetype) initWithObject:(id)object
                                      {
                                      if (!(self = [super init]))
                                      return nil;

                                      _object = object;

                                      return self;
                                      }
                                      @end

                                      @implementation UIImagePickerController (PLUS)

                                      // MARK: - Create a weak stored property in extension
                                      - (id)weakObjectForKey:(const void*)key {
                                      WeakObjectContainer *container = objc_getAssociatedObject(self, key);
                                      return [container object];
                                      }

                                      - (void)setWeakObject:(id)object forKey:(const void*)key {
                                      WeakObjectContainer *container = [[WeakObjectContainer alloc] initWithObject:object];
                                      objc_setAssociatedObject(self, key, container, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
                                      }

                                      // MARK: - Create a weak property for scrollView
                                      - (UIScrollView *)scrollView {
                                      return [self weakObjectForKey:_cmd];
                                      }

                                      - (void)setScrollView:(UIScrollView *)scrollView {
                                      [self setWeakObject:scrollView forKey:@selector(scrollView)];
                                      }

                                      // MARK: - Create a weak property for cropView
                                      - (UIView *)cropView {
                                      return [self weakObjectForKey:_cmd];
                                      }

                                      - (void)setCropView:(UIView *)cropView {
                                      [self setWeakObject:cropView forKey:@selector(cropView)];
                                      }

                                      // MARK: - Fix cannot move editing xox
                                      - (void)fixCannotMoveEditingBox {
                                      if (!self.scrollView || !self.cropView) {
                                      UIView *view = [self view];
                                      self.scrollView = [self findScrollView:view];
                                      self.cropView = [self findCropView:view];

                                      if (self.scrollView && self.cropView) {
                                      CGFloat top = self.cropView.frame.origin.y;
                                      CGFloat bottom = ({
                                      self.scrollView.frame.size.height - self.cropView.frame.size.height - self.cropView.frame.origin.y;
                                      });
                                      self.scrollView.contentInset = UIEdgeInsetsMake(top, 0, bottom, 0);
                                      self.scrollView.contentOffset = CGPointMake(0, -1);
                                      }
                                      }

                                      __weak typeof(self) weakself = self;
                                      dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC);
                                      dispatch_after(delay, dispatch_get_main_queue(), ^(void){
                                      __strong typeof(weakself) strongself = weakself;
                                      [strongself fixCannotMoveEditingBox];
                                      });
                                      }

                                      - (UIScrollView *)findScrollView:(UIView *)view {
                                      if ([view isKindOfClass:[UIScrollView class]]) {
                                      return (UIScrollView *)view;
                                      }
                                      for (UIView *subview in [view subviews]) {
                                      UIScrollView *view = [self findScrollView:subview];
                                      if (view) {
                                      return view;
                                      }
                                      }
                                      return nil;
                                      }

                                      - (UIView *)findCropView:(UIView *)view {
                                      CGFloat width = [[UIScreen mainScreen] bounds].size.width;
                                      CGSize size = [view frame].size;
                                      if (size.width == width && size.height == width) {
                                      return view;
                                      }
                                      for (UIView *subview in [view subviews]) {
                                      UIView *view = [self findCropView:subview];
                                      if (view) {
                                      return view;
                                      }
                                      }
                                      return nil;
                                      }

                                      @end


                                      then call it



                                      [imagePickerController fixCannotMoveEditingBox];






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 23 '18 at 3:16









                                      yyckingyycking

                                      22128




                                      22128























                                          -1














                                          A workaround that solved it is to add an entry in info.plist with "View controller-based status bar appearance" set to NO






                                          share|improve this answer




























                                            -1














                                            A workaround that solved it is to add an entry in info.plist with "View controller-based status bar appearance" set to NO






                                            share|improve this answer


























                                              -1












                                              -1








                                              -1







                                              A workaround that solved it is to add an entry in info.plist with "View controller-based status bar appearance" set to NO






                                              share|improve this answer













                                              A workaround that solved it is to add an entry in info.plist with "View controller-based status bar appearance" set to NO







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Apr 18 '17 at 14:27









                                              Josep AlsinaJosep Alsina

                                              1,10679




                                              1,10679






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12630155%2fuiimagepicker-allowsediting-stuck-in-center%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  To store a contact into the json file from server.js file using a class in NodeJS

                                                  Redirect URL with Chrome Remote Debugging Android Devices

                                                  Dieringhausen