iPhone SDK UIView绘制矩形和方向改变

发布于 11-18 00:46 字数 1621 浏览 4 评论 0原文

我写了这段代码...plotView是通过drawRect方法以编程方式绘制的...问题是当我更改设备方向时...所有视图都未正确缩放...自动调整大小蒙版有什么问题?我应该玩 setNeedsDisplay 或类似的吗?

提前致谢!

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];

if (self) {

    self.autoresizesSubviews = YES;
    self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    CGRect plotFrame = CGRectMake(0, 0, 1500, self.frame.size.height);

    // Initialization code.
    scrollView = [[UIScrollView alloc] initWithFrame:frame];
    scrollView.backgroundColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:0.4];
    scrollView.scrollEnabled = YES;
    scrollView.autoresizesSubviews = YES;
    scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    scrollView.showsHorizontalScrollIndicator = YES;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.alwaysBounceHorizontal = NO;
    scrollView.bounces = YES;
    scrollView.contentSize = CGSizeMake(plotFrame.size.width, plotFrame.size.height);
    scrollView.contentMode = UIViewContentModeScaleAspectFit;
    scrollView.delegate = self;
    //scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [self addSubview:scrollView];

    plotView = [[PlotView alloc] initWithFrame:plotFrame];
    plotView.backgroundColor = [UIColor clearColor];
    plotView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [scrollView addSubview:plotView];
    [plotView release];

    [scrollView release];
}

return self;

}

I've wrote this code... plotView is drawn programmatically by drawRect method... the problem is when I change the device orientation... all the views are not scaled properly... what's the matter with the autoresizing mask? should I play with setNeedsDisplay or similar?

Thanks in advance!

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];

if (self) {

    self.autoresizesSubviews = YES;
    self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    CGRect plotFrame = CGRectMake(0, 0, 1500, self.frame.size.height);

    // Initialization code.
    scrollView = [[UIScrollView alloc] initWithFrame:frame];
    scrollView.backgroundColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:0.4];
    scrollView.scrollEnabled = YES;
    scrollView.autoresizesSubviews = YES;
    scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    scrollView.showsHorizontalScrollIndicator = YES;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.alwaysBounceHorizontal = NO;
    scrollView.bounces = YES;
    scrollView.contentSize = CGSizeMake(plotFrame.size.width, plotFrame.size.height);
    scrollView.contentMode = UIViewContentModeScaleAspectFit;
    scrollView.delegate = self;
    //scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [self addSubview:scrollView];

    plotView = [[PlotView alloc] initWithFrame:plotFrame];
    plotView.backgroundColor = [UIColor clearColor];
    plotView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [scrollView addSubview:plotView];
    [plotView release];

    [scrollView release];
}

return self;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文