2016-03-04 24 views
0

我有一個scrollView其中我創建了一個新的CAShapeLayer。我想要myCAShapeLayer初始屏幕外,所以我必須向下滾動才能看到它。如何在scrollView中使用CAShapeLayer

這是我的滾動屏幕viewControler.m文件:

[myScrollScreen setScrollEnabled:YES]; 
[myScrollScreen setContentSize:CGSizeMake(320, 1000)]; 
[myScrollScreen setFrame:CGRectMake(0, 0, 320, 568)]; 
// the view controller size is also set to freeform 320,1000 
CAShapeLayer* myLayer; 
myLayer = [[CAShapeLayer alloc] init]; 
CGPoint myCenter = CGPointMake(someX, Y_seeBellow); 
myLayer.path = [UIBezierPath bezierPathWithArcCenter:myCenter radius:50 startAngle:-(M_PI/2.0) endAngle:3.0*M_PI/2.0 clockwise:YES].CGPath; 

現在,如果我集合Y到viewControler height * 0.5f - 我可以在屏幕中央看到myLayer。如果我將Y設置爲viewController height * 1.2f - 我向下滾動時看不到myLayer(其他事情像按鈕我可以看到這種方式)。如果我將Y設置爲myScrollView.boundsframe.size.height * 0.5f,則圖層保持不動 - 不滾動。有任何想法嗎?

回答

0

請注意,像這樣的設置框架將不再適用於不同大小的iPhone,我強烈建議使用Autolayout來代替。

首先,您需要在UIScrollView中添加您的形狀圖層。你的contentSize基本上是你可以放置你的形狀的地方。

您不應該修改您的視圖控制器高度。應該設置滾動視圖大小(如果滾動視圖爲全屏),其大小與ViewController相同。然後添加一個貝塞爾路徑Y_seeBellow到值self.view.frame.size.height+radius/2

然後你的形狀將被初始化在scrollview的可見部分底部的下方。