ユーザーがUITextViewのサイズを変更できるようにしたいのですが。UITextViewの右下隅にボタンを表示します。たとえば、ユーザーがボタンを移動すると、UITextViewがそれに続き、サイズが変更されます。
これは問題なく機能しますが、テキストスペースの動作がおかしいです。サイズ変更中にテキストスペースがどんどん小さくなっていくようです。したがって、サイズを大きく変更して、大きなフレームに移動してから小さなフレームに移動すると、テキストスペースがフレームよりも小さくなります。
- (id) init{//My subclass of UITextView
    self = [super init];
    if(self){
        //Resize button
        //Init ResizeButton
        self.resizeButton = [[UIButton alloc]init];
        //Image
        [self.resizeButton setImageForAllState:[UIImage imageNamed:@"Isosceles-right-triangle.png"]];
        //Target
        [self.resizeButton addTarget:self action:@selector(wasDragged:withEvent:) forControlEvents:UIControlEventTouchDragInside];
        [self.resizeButton addTarget:self action:@selector(wasDragged:withEvent:) forControlEvents:UIControlEventTouchDragOutside];
        //Add to view
        [self addSubview:resizeButton];
        //Self
        //text font
        [self setFont:[UIFont fontWithName:@"papyrus" size:17]];
    }
    return self;
}
- (void)wasDragged:(UIButton *)button withEvent:(UIEvent *)event
{
//  NSLog(@"wasDragged");// get the touch
    UITouch *touch = [[event touchesForView:button] anyObject];
    // get delta
    CGPoint previousLocation = [touch previousLocationInView:button];
    CGPoint location = [touch locationInView:button];
    CGFloat delta_x = location.x - previousLocation.x;
    CGFloat delta_y = location.y - previousLocation.y;
    // move button
    button.center = CGPointMake(button.center.x + delta_x,
                                button.center.y + delta_y);
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width+ delta_x, self.frame.size.height+ delta_y);
}
ビューもドラッグ可能です
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    // Calculate offset
    CGPoint pt = [[touches anyObject] locationInView:self];
    float dx = pt.x - startLocation.x;
    float dy = pt.y - startLocation.y;
    CGPoint newcenter = CGPointMake(self.center.x + dx, self.center.y + dy);
    // Set new location
    self.center = newcenter;
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // Calculate and store offset, and pop view into front if needed
    CGPoint pt = [[touches anyObject] locationInView:self];
    startLocation = pt;
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
編集
サイズ変更前

サイズ変更

元のサイズに戻す
