ปรับขนาด UIScrollView ด้วย setcontentsize

ฉันกำลังพยายามปรับขนาด UIScrollView ภายใน UICOllectionViewCell แต่ไม่ได้ปรับขนาด

-(int)resizeScrollView:(int)height{

    NSLog(@"Before Scroll height %f",self.scrollView.frame.size.height);
    float currentHeight=self.scrollView.frame.size.height+height+200;
    NSLog(@"height %f",currentHeight);
    CGSize size=CGSizeMake(self.scrollView.frame.size.width ,
                           currentHeight + 10 );
    [self.scrollView setContentSize:size];    
    self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    NSLog(@"After Scroll height %f",self.scrollView.frame.size.height);

    return currentHeight;
}

person user1688346    schedule 22.04.2013    source แหล่งที่มา


คำตอบ (1)


การตั้งค่า contentSize จะปรับจำนวนพื้นที่โลจิคัลที่มุมมองเลื่อนเลื่อนไป คุณต้องตั้งค่า frame หรือ bounds เพื่อปรับขนาดของ scrollview ในมุมมองพาเรนต์

CGRect scrollFrame = self.scrollView.frame;
scrollFrame.size.height += height + 210;
self.scrollView.frame = scrollFrame;
person Seamus Campbell    schedule 22.04.2013
comment
บริบทที่คุณโทรหา -resizeScrollView คืออะไร? - person Seamus Campbell; 23.04.2013
comment
ใช่ มันเป็นการปรับขนาดมุมมองแบบเลื่อน ฉันลงเอยด้วยการสร้างเฟรมใหม่และเพิ่มลงใน scrollview - person user1688346; 23.04.2013