iPhone SDK UIView drawRect and orientation change
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.showsHorizontalScrollIndic开发者_Python百科ator = 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;
}
精彩评论