Iphone UIView要向下滑动的动画
我试图在UIImageView中向下滑动图像,但我不知道UIContentMode和animation属性的哪个组合是实现这一点的正确组合。 图像应始终具有相同的大小,不应拉伸。。。我想要的是,首先什么都看不见,然后框架延伸并显示图像 如果你明白我的意思,也许会更容易: 所以,这听起来很简单,但是我应该为UIImageView使用什么UIContentMode,我应该设置什么属性的动画?谢谢大家! 试试这段代码。 将UIIVIEVIEW视为图像视图。Iphone UIView要向下滑动的动画,iphone,objective-c,animation,uiview,uiviewanimation,Iphone,Objective C,Animation,Uiview,Uiviewanimation,我试图在UIImageView中向下滑动图像,但我不知道UIContentMode和animation属性的哪个组合是实现这一点的正确组合。 图像应始终具有相同的大小,不应拉伸。。。我想要的是,首先什么都看不见,然后框架延伸并显示图像 如果你明白我的意思,也许会更容易: 所以,这听起来很简单,但是我应该为UIImageView使用什么UIContentMode,我应该设置什么属性的动画?谢谢大家! 试试这段代码。 将UIIVIEVIEW视为图像视图。 imageView.contentMode
imageView.contentMode = UIViewContentModeScaleAspectFill;
CGRect imageRect = imageView.frame;
CGRect origImgRect = imageRect;
imageRect.size.height = 5;
imageView.frame = imageRect;
[UIView animateWithDuration:2.0
animations:^{imageView.rect = origImgRect;}
completion:^(BOOL finished){ }];
我在你的带领下也做了一个电影放映 我将动画无限期地重复,以便更容易用视频捕捉,但它可以在按下按钮时启动,也可以在原地冻结,显示popover及其内容,直到反转后再次隐藏 为此,我使用了核心动画,而不是为UIView设置动画,因为我想使用CALayer的mask属性隐藏popover,并使用滑动动画显示它 以下是我使用的代码(与视频中的代码相同): 注意:您必须将QuartzCore框架导入到项目中,并在头文件中写入这一行:
#import
告诉你这是否对你有用,或者你是否需要更多的帮助来设置它。嘿,我猜你是指imageView.frame,而不是.rect,对吗?然后发生的事情就可以看到了。但这只是将整个视图向下移动,我只希望图片保持在原位,但向下移动可见区域…是的,它是帧。实际上,我正在做的是首先将imageview框架的高度设置为5,以便只查看箭头。然后,我用动画设置实际高度。我想你可以很容易地调试这里的东西。你看过我在上面评论中链接的视频了吗?你会看到整个视图都在移动,而不是剪贴画的生长,用你的代码…哇,非常感谢你非常详细的回答!我以前从未和CALayer乱搞过,但你提供的代码正是我需要的。我将对此进行讨论。如何在动画显示后继续添加动画,而不是重复?谢谢
- (void)viewDidLoad
{
// Declaring the popover layer
CALayer *popover = [CALayer layer];
CGFloat popoverHeight = 64.0f;
CGFloat popoverWidth = 200.0f;
popover.frame = CGRectMake(50.0f, 100.0f, popoverWidth, popoverHeight);
popover.contents = (id) [UIImage imageNamed:@"popover.png"].CGImage;
// Declaring the mask layer
CALayer *maskLayer = [CALayer layer];
maskLayer.frame = CGRectMake(0, - popoverHeight, popoverWidth, popoverHeight);
maskLayer.backgroundColor = [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f].CGColor;
// Setting the animation (animates the mask layer)
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.y"];
animation.byValue = [NSNumber numberWithFloat:popoverHeight];
animation.repeatCount = HUGE_VALF;
animation.duration = 2.0f;
[maskLayer addAnimation:animation forKey:@"position.y"];
//Assigning the animated maskLayer to the mask property of your popover
popover.mask = maskLayer;
[self.view.layer addSublayer:popover];
[super viewDidLoad];
}