-1

从横向到纵向时,我有一个无法替换的小子视图。你可以在这里看到它。

在此处输入图像描述 在此处输入图像描述

视图的代码如下。

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
    }
4

1 回答 1

0

我认为您使用autoresizingMask了错误的方式。尝试将最后一行更改为:

pageNumberView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
于 2013-04-03T10:17:40.360 回答