如何在不调整大小的情况下旋转UITextView?

时间:2014-10-09 14:53:19

标签: ios uitextview

我正在尝试在我的VC中旋转UITextView。当我尝试旋转它时,UITextView调整其大小?

这是我的代码。

    - (void)viewDidLoad {

        [super viewDidLoad];
        self.edgesForExtendedLayout = UIRectEdgeNone;

        self.title = @"Signature View";

        [self.signatureView setLineWidth:2.0];
        self.signatureView.foregroundLineColor = [UIColor colorWithRed:0.204 green:0.596 blue:0.859 alpha:1.000];

         NSLog(@"contentsize: %.0f, %.0f", self.view.frame.size.width, self.view.frame.size.height); <-- this is (contentsize: 320, 568)

        self.howToTextView.frame = CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width); 

        [self.howToTextView setNeedsDisplay]; <-- to make it redraw 

        [self.howToTextView setTransform:CGAffineTransformMakeRotation(-90* M_PI/180)];

        NSLog(@"contentsize: %.0f, %.0f", self.howToTextView.contentSize.width, self.howToTextView.contentSize.height); <--- turns out to be (contentsize: 103, 138)same as on storyboard design

    }

UPDATE(使用此代码,uitextview就位,框架是正确的,但文本不会调整大小以填充uitextviews新的框架大小。它被困在底角?):

    - (void)viewDidLoad {

        [super viewDidLoad];
        self.edgesForExtendedLayout = UIRectEdgeNone;

        self.title = @"Signature View";

        [self.signatureView setLineWidth:2.0];
        self.signatureView.foregroundLineColor = [UIColor colorWithRed:0.204 green:0.596 blue:0.859 alpha:1.000];

         NSLog(@"contentsize: %.0f, %.0f", self.view.frame.size.width, self.view.frame.size.height);

        self.howToTextView = [[UITextView alloc] init];
        self.howToTextView.backgroundColor = [UIColor redColor];
        self.howToTextView.text = @"this is a good day. i am going to make millions today. Smile while on the phone as it is the best way to increase your business. I hope that you like this app as we have work really hard on it. Please sign your name or decline but if you decline then you understand you lose all  coverage.";

        [self.view addSubview:self.howToTextView];


        [self.howToTextView setTransform:CGAffineTransformMakeRotation(-90* M_PI/180)];
        self.howToTextView.frame = CGRectMake(0, 0, 80, self.view.frame.size.height);
        [self.howToTextView setNeedsDisplay];

        NSLog(@"contentsize: %.0f, %.0f", self.howToTextView.contentSize.width, self.howToTextView.contentSize.height);

    }

更新2:在UIView中粘贴textview使内容大小正确,但现在使用此代码,uitextview / uiview位于应用程序的右上角,即使我将它们设置为0,0表示x ,Y?不知道为什么会这样?

        self.howToTextView = [[UITextView alloc] init];
        [self.howToTextView setFrame:CGRectMake(0, 0, self.view.frame.size.height-20, 110)];
        self.howToTextView.backgroundColor = [UIColor redColor];
        self.howToTextView.text = @"this is a good day. i am going to make millions today. Smile while on the phone as it is the best way to increase your business. I hope that you like this app as we have work really hard on it. Please sign your name or decline but if you decline then you understand you lose all  coverage.";

        UIView *myRotateView = [[UIView alloc] init];
        [myRotateView setFrame:CGRectMake(0, 0, self.view.frame.size.height, 120)];
        [myRotateView setBackgroundColor:[UIColor greenColor]];
        [myRotateView addSubview:self.howToTextView];

        myRotateView.transform = CGAffineTransformMakeRotation(-90* M_PI/180);
        [[self view] addSubview:myRotateView];

0 个答案:

没有答案