我想制作一个按钮,将图像向上移动一帧高度,如果再次按下该按钮,则将图像移回一帧高度。
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 :(得分:0)
在按钮的touchUpInside事件中,您需要更改:
scrollView.contentOffset = CGPointMake(X,Y);//required value to scroll the scrollview
如果您只想移动imageview,可以使用:
[imageView setCenter:CGPointMake(X,Y)];//required value
答案 1 :(得分:0)
有些问题:
您是使用滚动视图进行其他操作,还是只是为了让图像移动?
您希望您的图片视图能够动画,然后向下或突然移动吗?
滚动视图非常复杂,如果你想要做的就是让你的视图动画,然后向下。要做到这一点,你应该看看UIView类方法animateWithDuration:animations:它是变体。