链接两个UITextView以滚动在一起滚动

时间:2018-02-18 11:32:56

标签: ios objective-c uitextview

我有两个文本视图,彼此相邻,有多行文字。

如何根据同时滚动其中一个来同时滚动它们?

1 个答案:

答案 0 :(得分:1)

首先

 @interface ViewController : UIViewController <UITextViewDelegate>

第二次使两个textViews分层

  tv1.delegate = self  

  tv2.delegate = self  

实施

-(void)scrollViewDidScroll:(UIScrollView *)inScrollView {

    self.tv1.contentOffset = inScrollView.contentOffset;

    self.tv2.contentOffset = inScrollView.contentOffset;

}

以下是演示txView

修改

·H

#import <UIKit/UIKit.h>

    @interface ViewController : UIViewController <UITextViewDelegate>

    @property (weak, nonatomic) IBOutlet UITextView *tv1;
    @property (weak, nonatomic) IBOutlet UITextView *tv2;

    @end

的.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.tv1.delegate = self;

     self.tv2.delegate = self;
}
- (void)scrollViewDidScroll:(UIScrollView *)inScrollView {

    self.tv1.contentOffset = inScrollView.contentOffset;

    self.tv2.contentOffset = inScrollView.contentOffset;

}