1

在我的应用程序中,我正在使用 UIScrollView,它具有 UIImageView(20) 来添加使用 - (void)populateScrollView方法的图像。

    - (void)populateScrollView
{
TonifyAppDelegate *appDelegate = (TonifyAppDelegate *)[UIApplication sharedApplication].delegate;
double x1 = 0, y1 = 3;
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];            
NSMutableArray *getEffectsImageData = [ud objectForKey:@"getimageeffects"];
imageViewsArray = [[NSMutableArray alloc] initWithCapacity:[getEffectsImageData count]];
for(int i = 0; i < [getEffectsImageData count]; i++)
{ 
    NSString *sfxUrlFileName = [ [getEffectsImageData objectAtIndex:i] lastPathComponent];
    NSLog(@"sfxUrlFileName: %@", sfxUrlFileName);
    NSData *imageData = [appDelegate readSongDataFromDocsDirectory:sfxUrlFileName];
     UIImage *image = [[UIImage alloc] initWithData:imageData];
    UIImageView *anImageView = [[UIImageView alloc]initWithImage:image];
    CGRect imageFrame = anImageView.frame;
    imageFrame.origin.x = x1;
    imageFrame.origin.y = y1;
    anImageView.frame = CGRectMake(x1, y1, 45, 41);
    anImageView.userInteractionEnabled = YES;
    [scrollView addSubview:anImageView];
    x1 += anImageView.frame.size.width + 3;
    if (anImageView && [anImageView isMemberOfClass: [UIImageView class]]) 
        [imageViewsArray addObject: anImageView];
}

NSLog(@"imageViewsArray:%@",imageViewsArray);
}

并识别我使用的 UIScrollView 中的触摸

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
    [scrollView addGestureRecognizer:singleTap];

同时我正在使用 NSTimer 运行歌曲,就像

myTimer = [NSTimer scheduledTimerWithTimeInterval:timeinterval target:self selector:@selector(**updatplayer**) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:myTimer forMode:NSRunLoopCommonModes];

updatePlayer方法中,我正在执行如下任务

- (void)updatplayer
{
TonifyAppDelegate *appDelegate = (TonifyAppDelegate *)[UIApplication sharedApplication].delegate;

if (mThresholdVal<mMainLoopLength) 
{
    mThresholdVal+=0.5; 
}
else
{
    mThresholdVal = 0.0;
}

if (divimageView)
{
    [divimageView removeFromSuperview];
}
if ([self isHeadsetPluggedIn]==NO) {
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

}
else
{
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride); 
}
NSString *cu=[NSString stringWithFormat:@"%2.f",audioPlayer.currentTime];
NSString *du=[NSString stringWithFormat:@"%2.f",audioPlayer.duration];

NSLog(@"LOOP cu Duration = %@",cu);
NSLog(@"LOOP du = %@",du);

int curenttime=(int)[cu intValue];
NSLog(@"LOOP current Duration = %2.f",audioPlayer.duration);
if(curenttime==0)
{
    [audioPlayer play];

    x=20;
}

mixdata = [NSMutableDictionary dictionary];
{
    [activityIndicator stopAnimating];
    activityIndicator.hidden = YES;

    [divimageView setFrame:CGRectMake(x, 87, 12, 144)];
    [self.view addSubview:divimageView];  

    x=x+1;

    if ((x>19 && x< 480) && appDelegate.songURL != NULL) {
         [avplayer play];
            NSLog(@"mixdata:%@", mixdata);

    }
    else if((x>19 && x< 480) &&  (appDelegate.songIntroUrl || appDelegate.songMidUrl || appDelegate.songChorusUrl) )
    {
        [audioPlayer play];
    }
if (x==xCord && yCord<235)
{
    [audioPlayer1 play];
}
if (x==recXcord) 
{
    recaudioPlayer.volume = 10.0;
    [recaudioPlayer play];
    [activityIndicator stopAnimating];
    activityIndicator.hidden = YES;

}

   if(appDelegate.xCordArray!=NULL && [appDelegate.tagArray count]>0)
   {

       for(int i = 0; i<[appDelegate.xCordArray count];i++)
       {
            if (i ==  0){
            NSLog(@"sfxCount in i==0......%d",sfxCount);
            NSLog(@"[appDelegate.xCordArray count] in i==0......%d",[appDelegate.xCordArray count]);
            NSLog(@"[appDelegate.mMixedSFXTrack2Array count] in i==0......%d",[appDelegate.mMixedSFXTrack2Array count]);

               if (sfxCount-1 !=  [appDelegate.xCordArray count])
               {
                   if ([appDelegate.xCordArray count] > [appDelegate.mMixedSFXTrack2Array count] )
                   {
                   mShouldBufferUpdate = TRUE;
                   sfxCount  = [appDelegate.xCordArray count];
                }
               }
           }

           if (x==[[appDelegate.xCordArray objectAtIndex:i] intValue] && appDelegate.imgDragXCodr<480)
           {
               int j = [[appDelegate.tagArray objectAtIndex:i] intValue];
                //mShouldBufferUpdate = TRUE;
               [self getSetSongData:j :x];
               [audioPlayer2 play];

           }
    }
   }
    if(appDelegate.xCordTrack3Array!=NULL && [appDelegate.track3tagArray count]>0)
    {
        for(int i = 0; i<[appDelegate.xCordTrack3Array count];i++)
        {
            if (i ==  0)
            {

                if (sfxCount3-1 !=  [appDelegate.xCordTrack3Array count])
                {
                        if ([appDelegate.xCordTrack3Array count] > [appDelegate.mMixedSFXTrack3Array count] )
                        {
                            mShouldBuffer3Update = TRUE;
                            sfxCount3 = [appDelegate.xCordTrack3Array count];
                        }
                    }
                }

            if (x==[[appDelegate.xCordTrack3Array objectAtIndex:i] intValue] && appDelegate.imgDragXCodr1<480)
            {
                int j = [[appDelegate.track3tagArray objectAtIndex:i] intValue];
                [self getSetSongData:j :x];
                [trac3AudioPlayer play]; //For SFX Sounds

            }
        }
    }

if (x == 480)
{
    x=20;
}
}
}

当我单击 scrollView 时,它会在 UIView(主视图)中生成一个图像,当时 NSTimer 正在暂停。

我们该如何解决这个问题。任何人都可以帮助或建议我。提前致谢。

4

0 回答 0