i have the following situation , i'm trying to make a photo editor and i need to do scale,translate and rotate operations for an image with around center of view
the problem is that if i apply translate after 90 degree translate left is translate top and the anchor point is not the center of the view after translation
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// ImageView
v = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 500)];
[v setBackgroundColor:[UIColor redColor]];
// ImageView's Image
UIImage *img = [UIImage imageNamed:@"_my.jpg"];
[v setImage:img];
v.contentMode = UIViewContentModeScaleAspectFit;
v.layer.anchorPoint = CGPointMake(0.5, 0.5);
[self.view setBackgroundColor:[UIColor clearColor]];
// UiView containing ImageView
vc = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 500)];
[vc addSubview:v];
[self.view addSubview:vc];
}
- (IBAction)Click:(id)sender {
// Translate
if ([sender tag] == 1) {
CGAffineTransform t0 = v.transform;
CGAffineTransform t1 = CGAffineTransformTranslate(t0, 10.0, 0.0);
v.transform = t1;
}
// Rotate
if ([sender tag] == 2) {
CGAffineTransform t0 = v.transform;
CGAffineTransform t1 = CGAffineTransformRotate(t0, DEGREES_TO_RADIANS(10));
v.transform = t1;
}
}
does anyone know how can i keep the center of view as the anchor point and translate after rotation to work properly ?
tx