当前位置: 首页 > 知识库问答 >
问题:

返回UIImageView的函数中的UILabel动画

弓智明
2023-03-14

我在iOS中动画我的UILabels时遇到了麻烦。我用这个线程作为参考(iOS标签或图像的动画移动),但它似乎对我不起作用。我还尝试了其他几个方法,它们也不起作用。

我只是想在设定的时间内将标签平稳地移动到另一个位置(我所说的平稳是指没有跳跃)。然而,当我测试它时,标签不会移动。这是我的密码。我已经把它缩短到了我认为可能存在的问题。因为除了动画之外,其他一切都很有效。

- (UIImageView *)createImageWithTransitionTo:(NSMutableArray *) nextPOIs
{
    //imageView is a UIImageView which will be the return value of this function
    imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed@"blank1.gif"]];

    //Initialize label and manipulate it for my needs
    UILabel * label = /.../;        

    //Create animation
    [UIView animateWithDuration:1.0 animations:^{
        label.frame = nextLabelFrame; //nextLabelFrame is a CGRect
    }];

    [imageView addSubView:label];
    return imageView;
}

我的直觉告诉我,这是因为动画是针对UIView的,我将标签作为子视图添加到UIImageView对象(即imageView)中。不过,我也尝试过[UIImageView animateWithDuration..]。是因为我在视图控制器之外的函数中使用它吗?我该怎么修?

共有2个答案

商麒
2023-03-14

试试这个吧,我觉得很管用。

- (UIImageView *)createImageWithTransitionTo:(NSMutableArray *) nextPOIs
{
    //imageView is a UIImageView which will be the return value of this function
    imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed@"blank1.gif"]];

    //Initialize label and manipulate it for my needs
    UILabel * label = /.../;  
     label.tag=10;

    [imageView addSubView:label];
    return imageView;
}

调用此函数后,从imageview读取带有标签10的标签,然后在该标签上应用动画代码。

常小白
2023-03-14

我相信你做得很好。在我看来,您需要稍微更改代码。我正在重新发布你的代码,只做了一点小改动。(如果我错了,请原谅)

- (UIImageView *)createImageWithTransitionTo:(NSMutableArray *) nextPOIs

{//ImageView是一个UIImageView,它将是这个函数的返回值ImageView=[[UIImageView alloc]initNevImage:[UIImage ImageNated@"blank1.gif"]];

//Initialize label and manipulate it for my needs
UILabel * label = /.../;        

//在设置动画之前添加标签

[imageView addSubView:label];

//Create animation
[UIView animateWithDuration:1.0 animations:^{
    label.frame = nextLabelFrame; //nextLabelFrame is a CGRect
}];


return imageView;

}

 类似资料:
  • 有没有可能创建一个函数,它将lambda函数作为参数(每个lambda函数使用参数),然后返回一个具有单个参数的新函数,并返回所有lambda函数的乘积? 以下是我的非工作示例: 所以本质上,你有一个函数,它需要4个lambda函数,每个函数使用参数。例如,的参数可以类似于。 然后返回一个名为的新函数,该函数的输出是所有lambda函数的乘积,并且有一个参数,该参数传递到的每个lambda函数的参

  • 我需要一个视图,包含(标题,图像,和细节),细节是关于一个文本视图。 我需要的是,允许滚动到所有视图,而不仅仅是TexView。在我的应用程序中,如果我禁用了滚动,则textview将被剪切,因为高度不是动态的: 在我的代码中,我是这样写的:

  • 我正在学习指针是如何工作的,但我不明白这段代码中的一件事。在void*函数中返回int就像一个咒语,但是返回float就不是了。

  • 我正在使用一个bash脚本,我想执行一个函数来打印返回值: 当我执行时,它不会打印“34”。为什么会这样呢?

  • 出于某种原因,在下面的递归函数中, 永远不递增p,也就是说字符串s永远不是一个回文,尽管在我的程序中,s确实是一个回文,次数相当少。但是在下面一行中它仍然返回false 是因为功能吗?s采用的一些值为:aaa、aba、AAAA、abbb、bab 我已确保s中没有前后空格 P、 S:我已经检查过了,x==n 示例输入: 输出0。回文:aaaaaa、abaaba、aaaaaa

  • 点击图像,图像会产生抖动。 [Code4App.com]