Closed ahanmal closed 8 years ago
Hi Ahan!
Hrmm, okay. What size do you want to set it to specifically? Would this be better solved by setting an initial aspect ratio, or do you need an explicit size?
The default crop box is set up in the layoutInitialImage
method inside TOCropView
, so if you can add some hooks to interact with the crop box each time after that one is called, that SHOULD let you do it.
You can use the below code to start with custom rect.
#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;
[self presentViewController:cropController animated:YES completion:nil];
cropController.toolbar.clampButtonHidden = YES;
cropController.toolbar.rotateButtonHidden = YES;
[cropController.cropView setAspectLockEnabledWithAspectRatio:CGSizeMake(1.74f, 2.20f) animated:NO];
}];
}
@arvindkumar-gr That's interesting. I didn't think about modifying the cropView
directly. But, doesn't that only change the aspect ratio, and not set a starting origin for the cropView
?
I've been trying to do it with the following:
frame.origin.x = floor((self.baseCropBoxFrame.origin.x/self.imageSize.width)*bounds.size.width*0.5f);
frame.origin.y = floor((self.baseCropBoxFrame.origin.y/self.imageSize.height)*bounds.size.height*0.5f);
frame.size.width = floor((self.baseCropBoxFrame.size.width/self.imageSize.width)*bounds.size.width);
frame.size.height = floor((self.baseCropBoxFrame.size.height/self.imageSize.height)*bounds.size.height);
self.cropBoxFrame = frame;
Where baseCropBoxFrame
is passed in during initialization and the one I want the crop frame to be. However, while it does adjust the crop frame, it's not the one I want. It has a different aspect ration. @TimOliver any reasons for the 0.5f
? Where is the origin that I should be making the crop frame in terms of? Thanks!
Um. Hang on. So you want to make a specific subregion of the image selected by default?
Um, I'm still not sure of what effect you want to create, but setting the cropBoxFrame
property only specifies the placement of the crop box as it appears on-screen, in no relation to the position to the actual image.
The image itself is controlled by the contentOffset
and contentZoom
properties of its parent UIScrollView
.
Closing this as it has gone unreplied for nearly 3 weeks.
Hi,
I've been modifying TOCropViewController so I can initialize it with a custom rect and am having some trouble doing that. I modified all the initializers and everything to accept the CGRect but I have no clue where to set it. I'm sure that this needs to happen in TOCropView, but am unsure. I've tried setting some instance variables in TOCropView and also calling
setCropBoxFrame
after initialization to no avail. Any ideas?Thanks, Ahan