我有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;
}
由于
答案 0 :(得分:1)
[self.scrollView addSubview:self.drawChart];
执行以下操作:
CGRect frame = self.drawChart.frame;
frame.origin = CGPointZero;
self.drawChart.frame = frame;