在视图控制器中更改视图

时间:2014-03-10 06:52:01

标签: ios objective-c uilabel

所以我想制作一个像7分钟锻炼的应用程序,所以在锻炼期间,视图会变为另一种锻炼,通常包括图像,计时器和显示锻炼名称的标签。这一切都是自动发生的,例如,

查看1.显示正在进行俯卧撑的人的图像,显​​示30秒的计时器,称为表格的标题。 30秒后,它将转换为新视图。 视图2.与上述相同但不同的图片和标题 查看3 .....等等。

我认为没有必要为所有练习制作不同的视图控制器,所以你们有什么建议我需要做些什么来做这样的事情。

2 个答案:

答案 0 :(得分:0)

没有必要更改视图。您也可以在同一视图上工作。假设您的30秒工作已完成,您也可以在同一视图中创建新活动。如果要移动到新的View,则可以将数据从一个视图传递到另一个视图。并打开新视图,其中一个代码是

[self.navigationController pushViewController:View animated:YES]; 

答案 1 :(得分:0)

试试这个

#import "ViewController.h"

@interface ViewController ()
{
UIView *baseView;
UILabel *titleLabel;
UIImageView *viewforPic;
float fadeDuration;
NSMutableArray *infoArray ;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];


NSArray *imagesArray=[[NSArray alloc]initWithObjects:@"red.png",@"blue.png",@"yellow.png",  nil];
NSArray *titleArray =[[NSArray alloc]initWithObjects:@"red",@"blue",@"yellow", nil];

infoArray =[[NSMutableArray alloc]init];
for (int i=0; i<imagesArray.count; i++) {
    NSMutableDictionary *dict =[[NSMutableDictionary alloc]init];
    [dict setObject:imagesArray[i] forKey:@"images"];
    [dict setObject:titleArray[i] forKey:@"titles"];
    [infoArray addObject:dict];
  //  [dict removeObjectsForKeys:keys];
}
NSLog(@"%@",infoArray);

baseView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 380)];
[self.view addSubview:baseView];
titleLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
titleLabel.textAlignment=NSTextAlignmentCenter;
[baseView addSubview:titleLabel];
viewforPic =[[UIImageView alloc]initWithFrame:CGRectMake(0, 60, 320, 320)];
[baseView addSubview:viewforPic];

[self showAnimationwithinfor:0];

}

-(void)showAnimationwithinfor :(int)tempIndex
{
titleLabel.text=[infoArray[tempIndex] objectForKey:@"titles"];
viewforPic.backgroundColor= [UIColor redColor];  //[temp[0] objectForKey:@"images"];

[UIView animateWithDuration:10.0f animations:^{
    baseView.alpha = 1.0f;
} completion:^(BOOL finished){
    [UIView animateWithDuration:10.0f animations:^{
        baseView.alpha = 0.0f;
        if (infoArray.count>tempIndex+1) {
         int tempedIndex=tempIndex+1;
            [self showAnimationwithinfor:tempedIndex];
        }
    }];
}];
}
@end