Basically I have a UITextView and when I rotate it the content size is wider than the frame size. This causes the text view to scroll horizontally, when there is no text outside of the frame. This behavior is not wanted.
UITextView *ingredientsTextView = [[[UITextView alloc] initWithFrame:CGRectMake(50, 100,315,300)] autorelease];
[ingredientsTextView setBackgroundColor:[UIColor clearColor]];
[ingredientsTextView setEditable:NO];
[ingredientsTextView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
[ingredientsTextView setFont:[UIFont fontWithName:@"Helvetica" size:18]];
[ingredientsTextView setText:ingredientsText];
ingredientsTextView.transform = CGAffineTransformMakeRotation((3.44*M_PI)/180);
[ingredientsView addSubview:ingredientsTextView];
I can't understand why this is happening. Even putting in a setContentSize
method causes it to scroll horizontally (only by about 5/10pts) even when the width is < 100!
Any ideas? Is it just a side effect of rotation?
Thanks Tom
I was also stuck with this problem.
The only solution which I found was to create an instance of UIView and add the UITextView as a subview. Then you can rotate the instance of UIView and UITextView will work just fine.
UITextView *myTextView = [[UITextView alloc] init];
[myTextView setFrame:CGRectMake(0, 0, 100, 100)];
UIView *myRotateView = [[UIView alloc] init];
[myRotateView setFrame:CGRectMake(20, 20, 100, 100)];
[myRotateView setBackgroundColor:[UIColor clearColor]];
[myRotateView addSubview:myTextView];
myRotateView.transform = CGAffineTransformMakeRotation(0.8);
[[self view] addSubview:myRotateView];
I think you should not rotate the textView, what you should rotate is the view under it. For example, the view of navigationController, or the content view of a viewController.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With