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