如何以编程方式在同一视图中添加动画图像和文本?

时间:2016-01-01 12:14:19

标签: ios objective-c animation uiimage uitextview

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

How I want the image and text to appear on the view

我已经考虑过顶部的图像动画和紧随其后的大量文本的代码。我想知道是否有人可以对它们进行审核并告诉我它们是否合适。

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

- (void)viewDidLoad
{
    [super viewDidLoad];

    // codes for image animation 

    // codes for large amount of text to be displayed

} 

图片动画代码

对于图像动画,我将使用5张图片: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];

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

感谢阅读。

1 个答案:

答案 0 :(得分:0)

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];
    }