2012-04-28 25 views
0

我想製作一個按鈕,將圖像向上移動一幀高度,如果再次按下該按鈕,則將圖像移回一幀高度。製作一個移動圖像的按鈕

http://imageshack.us/photo/my-images/140/72197925.png/ (溶液的插圖)

我嘗試使用盡可能少的代碼越好。

UIImage *image = [UIImage imageNamed:@"01bear.png"]; 
imageView = [[UIImageView alloc] initWithImage:image]; 
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame]; 
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:applicationFrame]; 
scrollView.contentSize = CGSizeMake(5760, 1); 

[scrollView addSubview:imageView]; 
[window addSubview:scrollView]; 
[window makeKeyAndVisible]; 

scrollView.delegate = self; 
scrollView.pagingEnabled = YES; 

回答

0

上按鈕的touchUpInside情況下,您需要更改:

scrollView.contentOffset = CGPointMake(X,Y);//required value to scroll the scrollview 

,如果你只希望ImageView的移動,你可以使用:

[imageView setCenter:CGPointMake(X,Y)];//required value 
0

一些問題:

您是否將滾動視圖用於其他用途,或者只是爲了讓圖像移動?

你想讓你的圖像視圖動起來,然後向下或突然移動?

如果所有你想做的事情都是讓你的視圖動起來然後向下,滾動視圖非常複雜。爲此,您應該查看UIView類的animateWithDuration方法:動畫:它是變體。