6

पर आधारित UIImageView एनीमेशन मुझे कस्टम पैटर्न के साथ ऑडियो लेवल विज़ुअलाइज़र बनाने की आवश्यकता है। मेरे पास पीएनजी के रूप में छवि सेट है। मेरे वर्तमान दृष्टिकोण) माइक्रोफोनवॉल्यूम लेवल फीडबैक

2) ध्वनि के स्तर के आधार पर UIImageView के लिए प्रासंगिक छवि लोड की ऑडियो स्तर प्राप्त करें इस

1 की तरह है।

// audio level timer 
self.levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.001 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES]; 

imageView

- (void)levelTimerCallback:(NSTimer *)timer { 
[self.audioRecorder updateMeters]; 
const double ALPHA = 0.05; 
double peakPowerForChannel = pow(10, (0.05 * [self.audioRecorder peakPowerForChannel:0])); 
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults; 

//NSLog(@"Average input: %f Peak input: %f Low pass results: %f", [self.audioRecorder averagePowerForChannel:0], [self.audioRecorder peakPowerForChannel:0], lowPassResults); 

if (lowPassResults > 0.0 && lowPassResults <= 0.05){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim1"]; 
} 
if (lowPassResults > 0.06 && lowPassResults <= 0.10){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim2"]; 
} 
if (lowPassResults > 0.11 && lowPassResults <= 0.15){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim3"]; 
} 
if (lowPassResults > 0.16 && lowPassResults <= 0.20){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim4"]; 
} 
if (lowPassResults > 0.21 && lowPassResults <= 0.25){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim5"]; 
} 
if (lowPassResults > 0.26 && lowPassResults <= 0.30){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim6"]; 
} 
if (lowPassResults > 0.31 && lowPassResults <= 0.35){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim7"]; 
} 
if (lowPassResults > 0.36 && lowPassResults <= 0.40){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim8"]; 
} 
if (lowPassResults > 0.41 && lowPassResults <= 0.45){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim9"]; 
} 
if (lowPassResults > 0.46 && lowPassResults <= 0.50){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim10"]; 
} 
if (lowPassResults > 0.51 && lowPassResults <= 0.55){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim11"]; 
} 
if (lowPassResults > 0.56 && lowPassResults <= 0.60){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim12"]; 
} 
if (lowPassResults > 0.61 && lowPassResults <= 0.65){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim13"]; 
} 
if (lowPassResults > 0.66 && lowPassResults <= 0.70){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim14"]; 
} 
if (lowPassResults > 0.71 && lowPassResults <= 0.75){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim15"]; 
} 
if (lowPassResults > 0.76 && lowPassResults <= 0.80){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim16"]; 
} 
if (lowPassResults > 0.81 && lowPassResults <= 0.85){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim17"]; 
} 
if (lowPassResults > 0.86 && lowPassResults <= 0.90){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim18"]; 
} 
if (lowPassResults > 0.86){ 
    imgViewRecordAnimation.image = nil; 
    imgViewRecordAnimation.image = [UIImage imageNamed:@"anim19"]; 
} 

} 

लेकिन उत्पादन एक असली विजुआलाइज़र एनीमेशन के रूप में चिकनी नहीं है। सबसे अच्छा तरीका क्या होना चाहिए? साझा करने के लिए कोई बेहतर तरीका साझा करें। छवियों

enter image description here

enter image description here

enter image description here

+0

ऐसा लगता है जैसे यह इस मुद्दे के समान हो सकता है: http://stackoverflow.com/questions/2834573/how-to-animate-the-change-of-image-in-an-uiimageview – dudeman

+0

आप क्यों हैं se tting image property ('imgViewRecordAnimation.image = nil;') से पहले हर बार छवि को शून्य पर सेट करना? – arturdev

उत्तर

3

यदि आपको लगता है छवि परिवर्तन झटकेदार लग रही है, तो के

युगल, तो आप बेहतर उन पर एनिमेशन लागू होते हैं। वैसे, आपको nil को imgViewRecordAnimation.image पर सेट करने की आवश्यकता नहीं है, क्योंकि आप हर समय उचित छवियां सेट कर रहे हैं, जो अनावश्यक देरी पेश करेंगे। यदि आप सभी बयानों को निष्पादित करते हैं, तो आप सभी को अगर सभी बयान भी दे सकते हैं।

समाधान पर आ रहा है, तो आप बस उस लिंक का अनुसरण कर सकते हैं जो @MileAtNobel पोस्ट किया गया है। या यदि आप अधिक कोड परिवर्तन नहीं करना चाहते हैं, तो आप backgroundColor संपत्ति पर सरल एनीमेशन लागू कर सकते हैं। आप टाइमर को भी हटा सकते हैं, नीचे दिए गए कोड को जांचें और देखें कि कोड अच्छा काम कर रहा है या नहीं। मैंने कोड को करीबी समानता के साथ अनुकूलित करने का भी प्रयास किया, मुझे उम्मीद है कि यह प्रदर्शन में सुधार करेगा।

BOOL flagToContinue ; //assign NO to this flag to stop updating the images 

-(void)levelTimerCallback 
{ 
    NSLog(@"Volume Logic Begins") ;//Volume level logic begins 
    [self.audioRecorder updateMeters]; 
    const double ALPHA = 0.05; 
    double peakPowerForChannel = pow(10, (0.05 * [self.audioRecorder peakPowerForChannel:0])); 
    lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults ; 
    NSLog(@"Volume Logic ends") ;//Volume level logic ends 

    [UIView animateWithDuration:0.001f 
       delay:0.0f 
      options: UIViewAnimationOptionCurveLinear 
     animations:^{ 
      mgViewRecordAnimation.backgroundColor = [UIColor colorWithPatternImage:[NSString stringWithFormat:@"anim%d", (int)ceil(lowPassResults * 20)]]; 
     } 
     completion:^(BOOL finished) { 
      if(finished && flagToContinue) [self levelTimerCallback]; 
    }]; 
} 
+0

उत्तर के लिए धन्यवाद, लेकिन फिर भी, सामान्य छवि एनीमेशन के रूप में चिकनी नहीं है – sajaz

+0

उस स्थिति में आपको देखना चाहिए कि वॉल्यूम को खोजने में कितना समय लग रहा है। शुरू करने से पहले और समाप्त होने से पहले टाइम स्टैंप लें (जैसा कि मेरे कोड में उल्लिखित है) और समय अंतर देखें, मुझे लगता है कि आपके वॉल्यूम लॉजिक में अधिक समय लग रहा है, यही कारण है कि एनिमेशन चिकनी नहीं हैं। – Trident

2

ठीक है, मैं आपको सीधा समाधान नहीं दूंगा, लेकिन एक समाधान का सुझाव देने का प्रयास करूंगा, जिसे आपको आजमाया जाना है। तो, छवि दृश्य की छवि को बदलने के बजाय, एक कस्टम नियंत्रण लिखें। दृश्य का उप-वर्ग बनाएं। सही विधि को ओवरराइड करें। उसमें, या तो आप नियंत्रण मूल्य के आधार पर आवश्यक पैटर्न खींच सकते हैं या आप छवि को स्वयं खींच सकते हैं। लेकिन पहला दृष्टिकोण अनुशंसित है। कस्टम ड्राइंग छवि को बदलने की तुलना में चिकनी है। कृपया इसे आज़माएं और मुझे यह काम बताएं।

संबंधित मुद्दे