2011-07-11 18 views
-1

我正在使用UIImageViews。我想要這樣的行爲:如果我們觸摸UIImageView它需要放大雙倍,如果用戶刪除他的手指設置UIImageView到手指的實際位置......我該怎麼辦?如何在iphone sdk中動畫的對象?

任何人都可以告訴我這個代碼嗎?

預先感謝

回答

0

U可以使用的UIScrollView爲此,具有的UIImageView作爲滾動視圖的子圖。

爲此,U需要子類UIScrollView來編寫自定義滾動視圖。它將具有UIScrollView的所有屬性。唯一的事情,你必須重寫touchesEnded:方法,它會通知superview。所以在superview中,你也可以將縮放比例設置爲1,使其達到實際的位置。

0

實現委託方法touchesBegan:withEvent:– touchesEnded:withEvent:

在觸摸開始方法改變的ImageView的幀到imageview的尺寸和在touchesEnded變化幀爲原始大小的兩倍。

而宣告圖像啓用它的用戶交互

UIImageView *imageview=[[UIImageView alloc] init]; 
    imageview.userInteractionEnabled=YES; 


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
imageview.frame=CGRectMake(0,0,20,20); 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
imageview.frame=CGRectMake(0,0,40,40); 
} 

TNX