iPhone SDK UIView绘制矩形和方向改变
我写了这段代码...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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论