Objective c UiScrollview内容在后台复制

Objective c UiScrollview内容在后台复制,objective-c,xcode,uiscrollview,Objective C,Xcode,Uiscrollview,我正在尝试创建一个简单的天气应用程序,我需要一个简单的图像在UIScrollView中滚动,但我注意到,当我将背景颜色设置为透明或透明时,图像在背景中是静态的,而在UIScrollView中滚动一个“副本”,因为一张图片抵得上千言万语,这是一个默认无图像的证明 这是Xcode中的层次结构。它只是一个带有图像的滚动视图 这是模拟器。我向左滚动了一点,你可以看到,背景中有一个静态的副本 如果我为scrollview设置了背景色,它就可以正常工作。图像可以滚动,副本不见了,但我需要它是透明的。 如

我正在尝试创建一个简单的天气应用程序,我需要一个简单的图像在
UIScrollView
中滚动,但我注意到,当我将背景颜色设置为透明或透明时,图像在背景中是静态的,而在
UIScrollView
中滚动一个“副本”,因为一张图片抵得上千言万语,这是一个默认无图像的证明

这是Xcode中的层次结构。它只是一个带有图像的滚动视图

这是模拟器。我向左滚动了一点,你可以看到,背景中有一个静态的副本

如果我为scrollview设置了背景色,它就可以正常工作。图像可以滚动,副本不见了,但我需要它是透明的。 如果值得一提的话,我正在虚拟机中运行它

这是将XIB文件添加到视图的代码

[[NSBundle mainBundle] loadNibNamed:@"WeatherForecastSlideView" owner:self options:nil];
[self addSubview:self.contentView];
-(id) init{
    self = [super init];
    if (self) {
        [self internalInit];
    }
}

-(id) initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self internalInit];
    }
    return self;
}

-(id) initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self internalInit];
    }
    return self;
}

我希望问题是清楚的,并为拼写错误/错误感到抱歉。

结果是构造函数方法上有一个拼写错误 init方法调用internalInit,它安装nib文件并将nib层次结构视图添加为类的子视图。问题是,从代码调用init方法来安装类,然后从框架调用initWithFrame来创建和放置视图

[[NSBundle mainBundle] loadNibNamed:@"WeatherForecastSlideView" owner:self options:nil];
[self addSubview:self.contentView];
-(id) init{
    self = [super init];
    if (self) {
        [self internalInit];
    }
}

-(id) initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self internalInit];
    }
    return self;
}

-(id) initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self internalInit];
    }
    return self;
}
因此,基本上更改是从init方法中删除对内部init的调用

-(id) init{
    self = [super init];
    return self;
}
-(void)internalInit{
    [[NSBundle mainBundle] loadNibNamed:@"WeatherForecastSlideView" owner:self options:nil];
    [self addSubview:self.contentView];
    self.scrollView.delegate = self;
    self.translatesAutoresizingMaskIntoConstraints = NO;
    NSLayoutConstraint* height = [self.heightAnchor constraintEqualToConstant:self.contentView.bounds.size.height];
    height.active = YES;
    height.priority = UILayoutPriorityDefaultHigh;
    NSLayoutConstraint* width = [self.widthAnchor constraintEqualToConstant:self.contentView.bounds.size.width];
    width.active = YES;
    width.priority = UILayoutPriorityDefaultHigh;
}
作为参考,这是internalInit方法

-(id) init{
    self = [super init];
    return self;
}
-(void)internalInit{
    [[NSBundle mainBundle] loadNibNamed:@"WeatherForecastSlideView" owner:self options:nil];
    [self addSubview:self.contentView];
    self.scrollView.delegate = self;
    self.translatesAutoresizingMaskIntoConstraints = NO;
    NSLayoutConstraint* height = [self.heightAnchor constraintEqualToConstant:self.contentView.bounds.size.height];
    height.active = YES;
    height.priority = UILayoutPriorityDefaultHigh;
    NSLayoutConstraint* width = [self.widthAnchor constraintEqualToConstant:self.contentView.bounds.size.width];
    width.active = YES;
    width.priority = UILayoutPriorityDefaultHigh;
}
如果多次调用该方法,将向当前视图添加更多的子视图,而这正是问题的根源