我想知道你是否可以帮助我在IOS中做这样的动画,我想我需要使用Offset来渲染滚动天气,并且可能使用相同的Offset来改变4个视图的高度......可能你帮我这个吗?
屏幕截图:
这是我到目前为止所做的...... :(同时我制作了我的天气对象)
CalculSize帮助我将屏幕划分为4个区域,以便知道如果手指位置在区域1中,它应该显示第一个视图
-(void) calculSize{
//Calcul of the size of each WeatherView (different for each phone)
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenHeight = screenRect.size.height;
// - 67 is the height of my top menu
_maxSize1 = (screenHeight - 67) / 4;
NSLog(@"%f", _maxSize1);
NSLog(@"%f", screenHeight);
}
然后我使用touchesMoved获取手指在屏幕上移动时的Y位置
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
//returns Y position
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
NSLog(@"Y: %f",location.y);
//tells me if i'm in the first part etc.
if (location.y > _maxSize1) {
_part1 = YES;
NSLog(@"%d", _part1);
}
else if (location.y < _maxSize1){
_part1 = NO;
NSLog(@"%d", _part1);
}
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:nil object:nil];
}
答案 0 :(得分:1)
您能告诉我们您已经做了什么吗?
一种简单的方法是制作您的自定义&#34; WeatherView&#34;在其中实现方法
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
捕捉用户互动并启动基本动画,如
[UIView animateWithDuration:ANIM_DURATION animations:^{
self.center = CGPointMake(self.center.x, self.center.y + yMove);
}
completion:^(BOOL finished) {
NSLog(@"anim is finished");
[self showLabel:moveToTop];
isAnimating = NO;
}];
在动画结束时,我启动第二个显示UILabel。
最重要的是,您需要一个viewController来管理这些自定义视图,例如使用自定义协议。
如果您希望执行拖动,可以通过在自定义视图上添加平移手势识别器来处理它:
UIPanGestureRecognizer* gest = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
然后拖动视图:
- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self];
self.center = CGPointMake(self.center.x,
self.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self];
}