Rotating a UITextView causes the content to be wider than the frame width

I basically 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 the frame. This behavior is not required.

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 do not understand why this is happening. Even turning on the method setContentSizemakes it scroll horizontally (only about 5/10 points), even when the width is <100

Any ideas? Is this just a side effect of rotation?

Thanks tom

+3
source share
2 answers

, textView, , , - . , navigationController viewController.

+3

.

, , UIView UITextView . UIView, UITextView .

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];
+4

Source: https://habr.com/ru/post/1772450/


All Articles