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;
4

2 回答 2

0

一些问题:

您是否将滚动视图用于其他事情,或者只是为了让您的图像移动?

你想让你的图像视图向上,然后向下,还是突然移动?

如果您想要做的只是让您的视图动画向上然后向下,则滚动视图非常复杂。为此,您应该查看 UIView 类方法 animateWithDuration:animations: 及其变体。

于 2012-04-28T22:14:26.450 回答
0

在按钮的 touchUpInside 事件上,您需要更改:

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

如果您只想移动图像视图,您可以使用:

[imageView setCenter:CGPointMake(X,Y)];//required value
于 2012-04-28T11:13:35.817 回答