1
我有一個UIView
矩形大小(414,736)。我製作了一個寬度爲ScrollView
的寬度爲50,高度爲50的高度比UIView
的大。當我將UIView
添加到ScrollView
時,UIView
保持水平狀態是確定,但在垂直方向上它位於ScrollView
的底部。所以我的滾動部分是最重要的部分。但我想UIView
留在頂部,底部成爲滾動區域。 如何將UIView
的特定位置放在ScrollView
上? 以下代碼顯示了ScrollView的實現方式。如何將視圖添加到特定位置的滾動視圖?
CGRect screenRect = [[UIScreen mainScreen] bounds];
self.scrollView=[[UIScrollView alloc] initWithFrame:screenRect];
self.scrollView.delegate = self;
self.scrollView.clipsToBounds = YES;
[self.scrollView addSubview:self.drawChart];
self.scrollView.contentSize=CGSizeMake(screenRect.size.width+100,screenRect.size.height+50);
self.scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
self.scrollView.backgroundColor = [UIColor colorWithRed:0.564 green:0.439 blue:0.561 alpha:1];
self.view=self.scrollView;
編輯:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect screenRect = [[UIScreen mainScreen] bounds];
//Database
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
// Build the path to the database file
databasePath = [[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent: @"RECORDS.db"]];
//scroll view
//
self.scrollView=[[UIScrollView alloc] initWithFrame:screenRect];
self.scrollView.delegate = self;
self.scrollView.clipsToBounds = YES;
[self.scrollView addSubview:self.drawChart];
CGRect frame = self.drawChart.frame;
frame.origin = CGPointZero;
self.drawChart.frame = frame;
self.scrollView.contentSize=CGSizeMake(screenRect.size.width+100,screenRect.size.height+50);
self.scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
self.scrollView.backgroundColor = [UIColor colorWithRed:0.564 green:0.439 blue:0.561 alpha:1];
self.view=self.scrollView;
}
感謝
不,它不起作用。 self.drawChart.frame具有(0,0)原點,儘管我沒有實現它。 – batuman
好吧...圖表視圖位於多遠? –
50,這是我爲ScrollView添加的大小比UIView大。 – batuman