2013-04-03 104 views
-1

從橫向到縱向,我有一個小的子視圖不能替代。你可以在這裏看到它。從縱向到橫向,視圖不會被替代

enter image description here enter image description here

爲視圖的代碼如下。

if ((self = [super initWithFrame:frame])) 
    { 
     self.autoresizesSubviews = YES; 
     self.userInteractionEnabled = YES; 
     self.contentMode = UIViewContentModeRedraw; 
     self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; 
     self.backgroundColor = [UIColor colorWithRed:(80/255.0) green:(169/255.0) blue:(53/255.0) alpha:0.8f]; 

     //CAGradientLayer *layer = (CAGradientLayer *)self.layer; 
     //UIColor *liteColor = [UIColor colorWithWhite:0.82f alpha:0.8f]; 
     //UIColor *darkColor = [UIColor colorWithWhite:0.32f alpha:0.8f]; 
     //layer.colors = [NSArray arrayWithObjects:(id)liteColor.CGColor, (id)darkColor.CGColor, nil]; 

     CGRect shadowRect = self.bounds; shadowRect.size.height = 4.0f; shadowRect.origin.y -= shadowRect.size.height; 

     ReaderPagebarShadow *shadowView = [[ReaderPagebarShadow alloc] initWithFrame:shadowRect]; 

     [self addSubview:shadowView]; // Add the shadow to the view 

     CGFloat numberY = (0.0f - (PAGE_NUMBER_HEIGHT + PAGE_NUMBER_SPACE)); 
     CGFloat numberX = ((self.bounds.size.width - PAGE_NUMBER_WIDTH)/2.0f); 
     CGRect numberRect = CGRectMake(numberX+280, numberY-644, PAGE_NUMBER_WIDTH, PAGE_NUMBER_HEIGHT); 

     pageNumberView = [[UIView alloc] initWithFrame:numberRect]; // Page numbers view 

     pageNumberView.autoresizesSubviews = YES; 
     pageNumberView.userInteractionEnabled = NO; 
     pageNumberView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | 
     UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | 
     UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 
     pageNumberView.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.4f]; 

     pageNumberView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f); 
     pageNumberView.layer.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.6f].CGColor; 
     pageNumberView.layer.shadowPath = [UIBezierPath bezierPathWithRect:pageNumberView.bounds].CGPath; 
     pageNumberView.layer.shadowRadius = 2.0f; pageNumberView.layer.shadowOpacity = 1.0f; 

     CGRect textRect = CGRectInset(pageNumberView.bounds, 4.0f, 2.0f); // Inset the text a bit 

     pageNumberLabel = [[UILabel alloc] initWithFrame:textRect]; // Page numbers label 

     pageNumberLabel.autoresizesSubviews = NO; 
     pageNumberLabel.autoresizingMask = UIViewAutoresizingNone; 
     pageNumberLabel.textAlignment = UITextAlignmentCenter; 
     pageNumberLabel.backgroundColor = [UIColor clearColor]; 
     pageNumberLabel.textColor = [UIColor whiteColor]; 
     pageNumberLabel.font = [UIFont systemFontOfSize:16.0f]; 
     pageNumberLabel.shadowOffset = CGSizeMake(0.0f, 1.0f); 
     pageNumberLabel.shadowColor = [UIColor blackColor]; 
     pageNumberLabel.adjustsFontSizeToFitWidth = YES; 
     pageNumberLabel.minimumFontSize = 12.0f; 

     [pageNumberView addSubview:pageNumberLabel]; // Add label view 

     [self addSubview:pageNumberView]; // Add page numbers display view 

     trackControl = [[ReaderTrackControl alloc] initWithFrame:self.bounds]; // Track control view 

     [trackControl addTarget:self action:@selector(trackViewTouchDown:) forControlEvents:UIControlEventTouchDown]; 
     [trackControl addTarget:self action:@selector(trackViewValueChanged:) forControlEvents:UIControlEventValueChanged]; 
     [trackControl addTarget:self action:@selector(trackViewTouchUp:) forControlEvents:UIControlEventTouchUpOutside]; 
     [trackControl addTarget:self action:@selector(trackViewTouchUp:) forControlEvents:UIControlEventTouchUpInside]; 

     [self addSubview:trackControl]; // Add the track control and thumbs view 

     document = object; // Retain the document object for our use 

     [self updatePageNumberText:[document.pageNumber integerValue]]; 

     miniThumbViews = [NSMutableDictionary new]; // Small thumbs 
    } 

回答

0

我認爲您使用的方式不正確,請使用autoresizingMask。 嘗試將最後一行更改爲:

pageNumberView.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
相關問題