Ios 移动父帧的一半';s的大小会将其一直移动(坐标加倍)?

Ios 移动父帧的一半';s的大小会将其一直移动(坐标加倍)?,ios,objective-c,Ios,Objective C,我不知道发生了什么事 我没有做什么特别的事 我有一个以编程方式创建的UIViewController,没有情节提要 然后我创建了一个没有任何特殊内容的UIView #import "SettingsView.h" @interface SettingsView() @property UIImageView* bg; @end @implementation SettingsView - (id)initWithFrame:(CGRect)frame { self = [super i

我不知道发生了什么事

我没有做什么特别的事

我有一个以编程方式创建的UIViewController,没有情节提要

然后我创建了一个没有任何特殊内容的UIView

#import "SettingsView.h"
@interface SettingsView()
@property UIImageView* bg;
@end
@implementation SettingsView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.bg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"happy.png"]];
        [self addSubview:self.bg];
    }
    return self;
}

-(void)layoutSubviews
{
    self.bg.frame = self.frame;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
我在VC中实例化它,当我想显示它时,我会:

-(void)showSettingsView
{
    self.settings.frame = self.view.frame;
    self.btnInfo.userInteractionEnabled = NO;
    self.btnPause.userInteractionEnabled = NO;
    self.btnSettings.userInteractionEnabled = NO;
    self.view.userInteractionEnabled = NO;
    [self.view addSubview:self.settings];
    CGRect frame = self.settings.frame;
    frame.origin.x = frame.size.width * 0.48;
    frame.origin.y = 0;
    self.settings.frame = frame;
}
它从屏幕的两倍(0.48*2=96%)开始,而不是在屏幕上看到大约一半的图像视图

我不明白为什么坐标是两倍或者什么的

当我检查框架时,我清楚地看到原点在150左右,这是iPhone宽度的一半

会发生什么


谢谢

可能是因为

-(void)layoutSubviews
{
    self.bg.frame = self.frame;
}
你应该使用你的自我对象的界限,而不是框架

-(void)layoutSubviews
{
    self.bg.frame = self.bounds;
}

很高兴我能帮忙!我自己也做过很多次。如果对你有效,记得把这个标记为答案。是的,不幸的是,这迫使我等了将近半个小时才能接受它,对不起。