1
votes

I have a UIView which is added as a subview to my view controller. I want to rotate the UIView to some arbitrary angle and then modify the width and height of view. I have a UITextField and button to set angles.

-(void) setAngle: (UIButton *) sender
{
    angle = [myText.text floatValue];
    angle *= (M_PI)/180.0;
    self.transform = CGAffineTransformMakeRotation(angle);
}

And two UISliders to modify the height and width accordingly.

-(void)sliderAction1:(id)sender
{
    w = (CGFloat)slider1.value;
    CGRect myRect= CGRectMake(x, y, w, h);
    self.bounds = myRect; 
}
-(void)sliderAction2:(id)sender
{
    h = (CGFloat)slider2.value;
    CGRect myRect= CGRectMake(x, y, w, h);
    self.bounds = myRect;  
}

I have done my research and found out that after using CGAffineTransformMakeRotation() I can not use setFrame. The problem with "bounds" is that it is modifying the width and height of UIView from both ends. i.e. the origin of UIView is also changing. Is there any way I can extend the width only from one end?

2

2 Answers

0
votes

You shouldn't be modifying bounds like that. Typically you do not modify the bounds property.

Try concatenating your transforms using

CGAffineTransformScale (not CGAffineTransformMakeScale). Using "Make" you are effectively resetting the transform matrix.

CGAffineTransformScale(self.rotationTransform, x, y);
0
votes
-(void)sliderAction1:(id)sender
{
 CGFloat w = (CGFloat)slider1.value;
 CGRect myRect= CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, w,      self.view.frame.size.height);
 self.view.frame = myRect;
}

it's working for me changes width from one side. change is very minute cause slider value is in between 0-1 so if multiply w by 100 or 1000 it will reflect in major

use this after multiply

 CGRect myRect= CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, w*100,      self.view.frame.size.height);