0
我有一種觀點認爲,如下所示:iOS版 - 調整大小UIScrollView的內容在運行時
紅色矩形(參照出口:self.redView)是把滾動視圖內(引用插座: self.scrollView)。當按下「更大」或「更小」按鈕時,紅色矩形展開/收縮其高度。
我的代碼是在這裏:
#import "s1cViewController.h"
@interface s1cViewController()
@end
@implementation s1cViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidLayoutSubviews {
[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:CGSizeMake(self.scrollView.frame.size.width, 600)];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnBiggerTouched:(id)sender {
[self resizeViewHeight:20];
}
- (IBAction)btnSmallerTouched:(id)sender {
[self resizeViewHeight:-20];
}
- (void)resizeViewHeight:(int)heightDelta {
[UIView animateWithDuration:0.2f animations:^{
// Resize scrollview height
/*self.scrollView.contentSize = CGSizeMake(self.scrollView.contentSize.width, self.scrollView.contentSize.height + deltaInputWrapperHeight);*/
// Resize categoryInputView height
CGRect rect = self.redView.frame;
rect.size.height += heightDelta;
self.redView.frame = rect;
}];
}
@end
當我改變矩形的高度,然後滾動,高度變回原來的大小。我如何防止這種情況?
有沒有一種方法來動畫? – user2562424
當然可以。最簡單的就是動畫約束的變化。請在此處查看我對此主題的完整討論:http://www.apeth.com/iOSBook/ch17.html#_animation_and_autolayout – matt