我正在以编程方式创建的UIView(parentView)中添加UITextView。 我通过addSubView调用将textView添加到此parentView并将其backgroundColor设置为clearColor。
每当我将backgroundColor设置为clearColor,然后滚动textView时,它就会滚动文本,但会留下相同的测试副本。
这是我的代码
-(void) setup
{
self.headerTextView = [[UITextView alloc] init];
self.footerTextView = [[UITextView alloc] init];
self.notificationsImageView = [[UIImageView alloc]initWithImage:
[UIImage imageNamed:@"notifications_bell_icon"]];
self.titleLabel = [[UILabel alloc] init];
self.notificationsImageView.translatesAutoresizingMaskIntoConstraints = NO;
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.headerTextView.backgroundColor = UIColor.clearColor;
self.headerTextView.editable = NO;
self.footerTextView.editable = NO;
self.titleLabel.numberOfLines = 0;
self.titleLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:self.titleLabel];
[self addSubview:self.headerTextView];
[self addSubview:self.notificationsImageView];
self.titleLabel.text = @"Test this";
NSMutableArray<NSLayoutConstraint *> *constraints = [NSMutableArray array];
[constraints addObject:[self.notificationsImageView.topAnchor constraintEqualToAnchor:self.availableGuide.topAnchor constant:16.0]];
[constraints addObject:[self.notificationsImageView.widthAnchor constraintEqualToConstant:88.0]];
[constraints addObject:[self.notificationsImageView.heightAnchor constraintEqualToConstant:88.0]];
[constraints addObject:[self.notificationsImageView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:0.0]];
[constraints addObject:[self.titleLabel.topAnchor constraintEqualToAnchor:self.notificationsImageView.bottomAnchor
constant:16.0]];
[constraints addObject:[self.titleLabel.centerXAnchor constraintEqualToAnchor:self.centerXAnchor]];
[self.titleLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[constraints addObject:[self.titleLabel.leadingAnchor constraintEqualToAnchor:self.availableGuide.leadingAnchor
constant:16.0]];
[constraints addObject:[self.titleLabel.trailingAnchor constraintEqualToAnchor:self.availableGuide.trailingAnchor
constant:-16.0]];
[constraints addObject:[self.headerTextView.topAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:16.0]];
[constraints addObject:[self.headerTextView.heightAnchor constraintLessThanOrEqualToConstant:200.0]];
[self.tableView setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[constraints addObject:[self.headerTextView.leadingAnchor constraintEqualToAnchor:self.availableGuide.leadingAnchor
constant:16.0]];
[constraints addObject:[self.headerTextView.trailingAnchor constraintEqualToAnchor:self.availableGuide.trailingAnchor
constant:-16.0]];
[constraints addObject:[self.headerTextView.bottomAnchor constraintEqualToAnchor:self.availableGuide.bottomAnchor]];
[self.headerTextView setText:@"dvmnbjh kjsdbkjsd kjbsdv kjbdsv kj fa kjvs d jdsg vdsj vdsj dsbij dgsjdsg dsik gdsjvds ewgb j ejgew j vwew ef v i fewmn jfwbfweb rlkjrglk jkbdgrjk kjndgfkjn kjbdfgkj kjbdbkjbdk kjbdfgkjbk jkbdg jg f fwuvvwj fwe jbfwe efwkjhkjew jhwefbkjbewk ijewfbiewbf iubewfiubwefiubef iwefb wefiuewfb wefiubwef wefibwef iweuf wfejhvwefh dvmnbjh kjsdbkjsd kjbsdv kjbdsv kj fa kjvs d jdsg vdsj vdsj dsbij dgsjdsg dsik gdsjvds ewgb j ejgew j vwew ef v i fewmn jfwbfweb rlkjrglk jkbdgrjk kjndgfkjn kjbdfgkj kjbdbkjbdk kjbdfgkjbk jkbdg jg f fwuvvwj fwe jbfwe efwkjhkjew jhwefbkjbewk ijewfbiewbf iubewfiubwefiubef iwefb wefiuewfb wefiubwef wefibwef iweuf wfejhvwefh ifwev ewfj"];
}
这是不滚动和滚动时的样子。
setUp
函数只是parentView中设置所有内容的函数。仅当将backgroundColor
设置为clearColor
时才会发生问题,如果我设置任何其他颜色,例如redColor
,则效果很好