2011-05-11 66 views
5

我有一個UIView,我在其上加載我的圖像視圖作爲子視圖。當我沒有設置錨點時,圖像顯示,但每當我設置錨點圖像不顯示。我也添加了QUARTZCore框架的工作。當我設置定位點時,我的圖像不加載

我加入我的代碼如下

CGRect apprect=CGRectMake(0, 0, 1024, 768); 
UIView *containerView = [[UIView alloc] initWithFrame:apprect1]; 
containerView.backgroundColor = [UIColor whiteColor]; 
[self.view addSubview:containerView]; 

handleView1= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"large.gif"]]; 
[handleView1 setAlpha:1]; 
//[handleView1 setFrame:CGRectMake(390, 172.00, 56.00, 316.00)]; 
handleView1.userInteractionEnabled = YES; 
handleView1.layer.anchorPoint=CGPointMake(490.0, 172.0); 
[containerView addSubview:handleView1]; 

回答

6

的問題是,你使用的anchorPoint值。您不會將幀的位置設置爲值。讓我引用蘋果:

的anchorPoint屬性是一個CGPoint 指定與位置座標對應 層的 範圍內的位置。定位點 指定界限 相對於位置屬性 的位置以及如何應用 作爲應用周圍 轉換的點。 單位座標系 (0.0,0.0)的值位於最接近 圖層的原點,並且(1.0,1.0)位於對角的 ,表示爲 。

enter image description here

看一看Layer Geometry and Transforms in the Core Animation Programming Guide瞭解更多詳情。

+0

非常感謝你尼克韋弗。非常感謝。 – Lena 2011-05-11 07:37:09

0

首先設置你的ImageView的框架,然後設置這樣

的ancherpoint [handleView1.layer setAnchorPoint:CGPointMake(1,1)];

相關問題