scrollView错误的位置xcode 5

时间:2014-01-22 09:58:06

标签: ios uiscrollview xcode5

我不知道为什么我总是被卷轴视图的位置问题困住...我只想在5像素距离的标签后显示滚动视图,但它在顶部有额外的余量。我正在使用storyboard - xcode 5.当我使用iOS 7测试时Scrollview正确定位,但在iOS 6模拟器中产生问题。

注意:我没有使用任何约束。

在故事板中,

enter image description here

iOS 6快照

enter image description here

iOS 7快照

enter image description here

简单的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    if([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;
    if([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)])
        self.automaticallyAdjustsScrollViewInsets = NO;

  //add subviews to scrollview

    _latestNewsLabel.layer.borderColor = [UIColor greenColor].CGColor;
    _latestNewsLabel.layer.borderWidth = 1.0;

    _latestNewsScroll.layer.borderColor = [UIColor blueColor].CGColor;
    _latestNewsScroll.layer.borderWidth = 1.0;

    self.view.backgroundColor = [UIColor whiteColor];
    _categoriesList = [NSArray arrayWithObjects:@"US World", @"World", @"Business", @"Political", @"Entertainment", @"Sports", @"IT", nil];
    selectedIndex = -1;

    [_collectionView registerClass:[CustomCollectionCell class] forCellWithReuseIdentifier:@"Category"];
    CollectionViewLayout *collLayout = [[CollectionViewLayout alloc] init];
    [self.collectionView setCollectionViewLayout:collLayout];    

}

-(void) viewWillAppear:(BOOL)animated{

    CGRect newFrame = _latestNewsScroll.frame;
    newFrame.origin.y = _latestNewsLabel.frame.origin.y + _latestNewsLabel.frame.size.height + 5;
    _latestNewsScroll.frame = newFrame;    

    newFrame = _collectionView.frame;
    newFrame.origin.y = _latestNewsScroll.frame.origin.y + _latestNewsScroll.frame.size.height + 10;
    _collectionView.frame = newFrame;

}

0 个答案:

没有答案