2017-11-10 5 views
0

私はアプリを開発中です。アプリの開発中に問題があります。 問題は次のとおりです。画像と音声を表示

私はUIImageViewとオーディオを持っています。配列に20個の画像があります。このUIImageViewに20個の画像を時間間隔内で表示する必要があります。画像とともに、オーディオを設定する必要があります。私は同じ時間に見る必要があります。つまり、同時に20枚の画像と音声が来るはずです。

私のコードは以下の通りです。

alphabetsStoreArray = [[NSMutableArray alloc]initWithObjects:@"a.png",@"b.png",@"c.png",@"d.png",@"e.png",@"f.png",@"g.png",@"h.png",@"i.png",@"j.png",@"k.png",@"l.png",@"m.png",@"n.png",@"o.png",@"p.png",@"q.png",@"r.png",@"s.png",@"t.png",@"u.png",@"v.png",@"w.png",@"x.png",@"y.png",@"z.png", nil]; 


    commonFunctionObject = [[SpeechCommonFunctions alloc]init]; 
    commonFunctionObject.isRecordComplete = NO; 
    counter = 0; 
    isMicPresent = YES; 
    _confirmationPopupView.hidden = true; 
    [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(repeatActionFire) userInfo:nil repeats:NO]; 

    // Do any additional setup after loading the view. 
} 

-(void)repeatActionFire 
{ 
    if(counter >= alphabetsStoreArray.count) 
    { 
     NSLog(@"finished"); 
     [_alphabetsShowImageView removeFromSuperview]; 
     [_speakerOrMicImageView removeFromSuperview]; 
     UIImageView *congratzView = [[UIImageView alloc]initWithFrame:self.view.frame]; 
     congratzView.image = [UIImage imageNamed:@"congratulation.png"]; 
     [self.view addSubview:congratzView]; 
     [self performSelector:@selector(navNew) withObject:nil afterDelay:3]; 

    } 

    else 
    { 
     [commonFunctionObject textToSpeechAction:alphabetsStoreArray :counter :_alphabetsShowImageView :_speakerOrMicImageView :isMicPresent]; 
     [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(ActionToCkeckRecordCompletion) userInfo:nil repeats:YES]; 
    } 
} 

-(void)ActionToCkeckRecordCompletion 
{ 
    if(commonFunctionObject.isRecordComplete) 
    { 
     _confirmationPopupView.hidden = false; 
    } 
} 
-(void)navNew 

{ 
    v11=[self.storyboard instantiateViewControllerWithIdentifier:@"maincontroller"]; 
    [self presentViewController:v11 animated:NO completion:nil]; 

} 
- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

/* 
#pragma mark - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    // Get the new view controller using [segue destinationViewController]. 
    // Pass the selected object to the new view controller. 
} */ 



-(IBAction)homebut:(id)sender{ 
    UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Title" 
                    message:@"Message" 
                  preferredStyle:UIAlertControllerStyleAlert]; 
    UIAlertAction* Home = [UIAlertAction 
           actionWithTitle:@"RETURN TO HOME" 
           style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) 
           { 

            v11=[self.storyboard instantiateViewControllerWithIdentifier:@"maincontroller"]; 
            [self presentViewController:v11 animated:NO completion:nil]; 


           }]; 
    UIAlertAction* Cancel = [UIAlertAction 
           actionWithTitle:@"CANCEL" 
           style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) 
           { 
                   }]; 
    [alert addAction:Cancel]; 
    [alert addAction:Home]; 



    [self presentViewController:alert animated:YES completion:nil]; 
} 
- (IBAction)playButtonAction:(id)sender 
{ 
    [commonFunctionObject recordPlayAction]; 
} 

- (IBAction)nextButtonAction:(id)sender 
{ 
    counter+=1; 
    _confirmationPopupView.hidden = true; 
    commonFunctionObject.isRecordComplete = NO; 
    if(commonFunctionObject.player.playing){[commonFunctionObject.player stop];} 
    [self repeatActionFire]; 
} 

- (IBAction)retryButtonAction:(id)sender 
{ 
    _confirmationPopupView.hidden = true; 
    commonFunctionObject.isRecordComplete = NO; 
    if(commonFunctionObject.player.playing){[commonFunctionObject.player stop];} 
    [self repeatActionFire]; 
} 

どのようにすればよいですか?

+0

オーディオシーク時間を取得し、画像の配列数で割った後、アニメーションの時間をUIImageviewに設定します。harish saran https://stackoverflow.com/questions/16585263/uiimage-animating-an-array-of-images – karthikeyan

+0

どのようにここで行うことができますか?コード – jesteena

答えて

0

これを試してみてください。これ以上のものが必要かもしれませんが、ここで正しい方向に向かうことができます。

-(IBAction)btnclicked:(id)sender { 
NSMutableArray *images = [[NSMutableArray alloc]init]; 
//all alloc does is allocate memory. The -init method is crucial to 
actually initialize the object into a working state. 

for (int imagenumber = 1; imagenumber <= 45; imagenumber++) { 
NSMutableString *myString = [NSMutableString stringWithFormat:@"%i.png", imagenumber]; 
[images addObject:[UIImage imageNamed:myString]]; 
} 
CGRect frame = CGRectMake(0.0, 0.0, 320, 460); 
UIImageView *imageview = [[UIImageView alloc] initWithFrame:frame]; 
imageview.contentMode = UIViewContentModeScaleToFill; 

NSURL *url = [NSURL fileURLWithPath:[NSString 
stringWithFormat:@"%@/giggity stick around.wav", [[NSBundle mainBundle] 
resourcePath]]]; 
soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url 
error:nil]; 
soundPlayer.volume = 1; 
[soundPlayer play];  

imageview.animationImages = images; 

imageview.animationDuration = 3.2; 

imageview.animationRepeatCount = 1; 

[imageview startAnimating]; 

[self.view addSubview:imageview]; 

} 

オーディオを再生するには、AVFoundationを使用します。

+0

は、この回答を確認してください? @jesteena – Mukesh

関連する問題