Closed BhaveshDhaduk closed 11 years ago
hey @googler2013 you most definitely can.
If you remove rotational abilities it's quite simple.
I added a simple method calls fixBounds which I call when there are no touches left. Shown below:
-(void)fixBounds{
CGFloat yOffset = 0;
CGFloat xOffset = 0;
if(self.imageView.frame.origin.x > 0){
xOffset = -self.imageView.frame.origin.x;
}else if(self.imageView.frame.origin.x+self.imageView.frame.size.width < 320){
xOffset = 320-(self.imageView.frame.origin.x+self.imageView.frame.size.width);
}
if (self.imageView.frame.origin.y > self.cropRect.origin.y) {
yOffset = -(self.imageView.frame.origin.y - self.cropRect.origin.y);
}else if((self.imageView.frame.origin.y + self.imageView.frame.size.height) <
(self.cropRect.origin.y + self.cropRect.size.height)){
yOffset = self.cropRect.origin.y + self.cropRect.size.height - (self.imageView.frame.origin.y+self.imageView.frame.size.height);
}
if(xOffset || yOffset){
self.view.userInteractionEnabled = NO;
CGAffineTransform transform =
CGAffineTransformTranslate(self.imageView.transform,
xOffset/self.scale, yOffset/self.scale);
[UIView animateWithDuration:kAnimationIntervalTransform delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.imageView.transform = transform;
} completion:^(BOOL finished) {
self.view.userInteractionEnabled = YES;
}];
}
}
The other thing to keep in mind, is if you want landscape image to show up fitting tight in the cropRect, you should also add something along the lines of this to your reset method
if(aspect < 1){
h = CGRectGetHeight(self.cropRect);
w = h/aspect;
}
and make sure the view.layer.masksToBounds = YES otherwise you will see the landscape image stick out when you push it onto a navigation Controller
For remove rotation, i got the point and remove gesture.
Where I need to implement this methods fixBounds and the other aspect < 1.
I've added a 'checkBounds' setting. It uses dmitric ideas with some modifications.
Can I bound image to not scale below to corp area, as of now i can scale image as smaller then corp area. that's why at the time I am corp the image black background will come with result image.