如果一个滚动,则链接两个 UITextView 一起滚动
Linking two UITextView to scroll together if one is scrolled
我有两个并排的文本视图,其中包含多行文本。
如何根据同时滚动其中一个来使它们一起滚动?
第一个
@interface ViewController : UIViewController <UITextViewDelegate>
第二个使两个 textView 都延迟
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;
}
我有两个并排的文本视图,其中包含多行文本。
如何根据同时滚动其中一个来使它们一起滚动?
第一个
@interface ViewController : UIViewController <UITextViewDelegate>
第二个使两个 textView 都延迟
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;
}