【问题标题】:How to add animate images and text in the same view programatically?如何以编程方式在同一视图中添加动画图像和文本?
【发布时间】:2016-01-01 12:14:19
【问题描述】:

我目前正在学习 iOS 开发,我想开发一个 iOS 应用程序,其中在 View Controller 的开头顶部有一个动画图像,并且在它之后有很多文本。请看下图:

我已经考虑了顶部的图像动画和紧随其后的大量文本的代码。我想知道是否有人可以检查它们并告诉我它们是否良好。

图像动画和大量文本的代码将放在控制器实现文件的viewDidLoad方法中,如下所示:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // codes for image animation 

    // codes for large amount of text to be displayed

} 

图像动画代码

对于图像动画,我将使用 5 张 png 图片:A.png、B.png、C.png、D.png 和 E.png。幻灯片将从 A 开始,然后移动到 B,然后到 C,到 D,最后到 E。所有 5 张图片都添加到我在 Xcode 中的项目中。以下是代码:

NSArray *imagelist = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"A.png"], [UIImage imageNamed:@"B.png"], [UIImage imageNamed:@"C.png"], [UIImage imageNamed:@"D.png"], [UIImage imageNamed:@"E.png"],nil];

UIImageView *animationImageView = [[UIImageView alloc] initWithFrame: CGRectMake(5,5,90,180)];
animationImageView.animationImages = imagelist;
animationimageView.animationDuration = 10;
[self.view addSubView:animationimageView];
[animationImageView startAnimating];

大量的文本代码

对于文本,我没有添加所有必要的文本....因为还有很多。这就是为什么我需要文本对象是可滚动的。以下是代码:

UITextView *largeText = [[UITextView alloc] initWitthFrame: CGRectMake(5,100,90,180)];
largeText.text = @"In organizations, we must work with and for others. To be able to mutually achieve our goals, we must be able to relate to others effectively. These leadership tips will help you do just that:
1)Catch people doing things right and then let them know that they are doing things right
2)Use feedback to stay informed about what other people are doing in your area of responsibility and authority
3)Have regular, focused meetings regarding the projects that you are responsible for
4)Provide adequate instructions. Time is lost if things are not done correctly
5)Train others to do jobs. You cannot do them all, nor can others do them if they have not been trained
6)Expect others to succeed. It becomes a self-fulfilling prophecy when you believe others are loyal, dedicated and doing a good job";
largeText.font = [UIFont fontWithName:@"TimesNewRomanPSMT" size:18];
largeText.editable = NO;
largeText.scrollEnabled = YES;
[self.view addSubView:largeText];

请检查代码,有人可以告诉我代码是否正确。

感谢阅读。

【问题讨论】:

    标签: ios objective-c animation uiimage uitextview


    【解决方案1】:
    NSArray *imagelist = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"A.png"], [UIImage imageNamed:@"B.png"], [UIImage imageNamed:@"C.png"], [UIImage imageNamed:@"D.png"], [UIImage imageNamed:@"E.png"],nil];
    
    UIImageView *animationImageView = [[UIImageView alloc] initWithFrame: CGRectMake(5,5,90,180)];
    [self.view addSubView:animationimageView];
    
     NSTimeInterval delay=0.0;
     for (NSInteger i=0; i<[imagelist count]; i++) {
             delay+=3.0;
            [UIView animateWithDuration:0.5 delay:delay options:UIViewAnimationOptionCurveLinear animations:^{
                animationImageView.image=[imagelist objectAtIndex:i];
            }completion:nil];
        }
    

    【讨论】:

    • 感谢您的回答。你能解释一下代码吗?谢谢
    • 请解释为什么我自己的代码在我的帖子中不起作用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多