こんにちは、私はレシピとその詳細に基づいたアプリケーションに取り組んでいます。ここに添付した詳細ページのスクリーン ショットを撮りました。iPhone マイクを介して Blow を検出でき、また、プロジェクトのクラスで「pageImage」として名前を付けた画像をアニメーション化します。以下のコードを使用して
-(void)viewDidLoad
[self paperDetails];
-(void)paperDetails
{
NSMutableArray *arrayNum =[[NSMutableArray alloc] init];
[arrayNum addObject:@"1:"];
[arrayNum addObject:@"2:"];
[arrayNum addObject:@"3:"];
[arrayNum addObject:@"4:"];
CGFloat xOffset=0;
CGFloat yOffset=0;
CGFloat imgWidth =31.0;
CGFloat imgHeight =30.0;
int rowNumber =0;
int imgInc = 0;
for (int i=0; i<[arrayNum count]; i++) {
//CALCULATE xOffset FOR EACH IMAGE
if (i%1 == 0) {
xOffset =15;
}
//CALCULATE yOffset FOR EACH IMAGE
if (imgInc == 1) {
imgInc = 0;
rowNumber = rowNumber + 1;
}
imgInc = imgInc+1;
yOffset =(imgHeight+30)* rowNumber;
NSLog(@"yOffset %f",yOffset);
UILabel *recipeTitle = [[UILabel alloc]init];
[recipeTitle setTag:i];
[recipeTitle setBackgroundColor:[UIColor clearColor]];
[recipeTitle setFrame:CGRectMake(xOffset, yOffset+100, imgWidth, imgHeight)];
//titleLabel.text=[[appDelegate.activeCardArr objectAtIndex:i] objectForKey:@"Card_Title"];
recipeTitle.text =[arrayNum objectAtIndex:i];
recipeTitle.textColor =[UIColor colorWithRed:0 green:0.392 blue:0 alpha:1];
recipeTitle.font =[UIFont fontWithName:@"Noteworthy-Bold" size:23.0];
recipeTitle.textAlignment =UITextAlignmentCenter;
[paperImage addSubview:recipeTitle];
[recipeTitle release];
}
for (int i=0; i<=3; i++) {
//CALCULATE xOffset FOR EACH IMAGE
if (i%1 == 0) {
xOffset =50;
}
//CALCULATE yOffset FOR EACH IMAGE
if (imgInc == 1) {
imgInc = 0;
rowNumber = rowNumber + 1;
}
imgInc = imgInc+1;
yOffset =(imgHeight+30)* rowNumber;
NSLog(@"yOffset %f",yOffset);
UILabel *paperDetail = [[UILabel alloc]init];
[paperDetail setBackgroundColor:[UIColor clearColor]];
[paperDetail setFrame:CGRectMake(xOffset, yOffset-165, imgWidth+250, imgHeight+50)];
//titleLabel.text=[[appDelegate.activeCardArr objectAtIndex:i] objectForKey:@"Card_Title"];
paperDetail.text =@"keep stirring until cooked";
paperDetail.textColor =[UIColor colorWithRed:0.2 green:0 blue:0.098 alpha:1];
paperDetail.font =[UIFont fontWithName:@"Noteworthy-Bold" size:23.0];
paperDetail.textAlignment =UITextAlignmentCenter;
[paperImage addSubview:paperDetail];
[paperDetail release];
}
//*************Blow Detection Code Here **********//
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.005 target: self selector: @selector(levelTimerCallback:) userInfo:nil repeats:YES];
}
else{
// NSLog([error description]);
}
}
- (void)levelTimerCallback:(NSTimer *)timer {
[recorder updateMeters];
const double ALPHA = 0.05;
double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
if (lowPassResults >0.55)
{
if (!self.blowDetected) {
self.blowDetected = TRUE;
// NSLog(@"Mic blow detected");
[self changeFrame];
}
} else
{
// NSLog(@"Blow not detected with residual power: %f", lowPassResults);
self.blowDetected = FALSE;
}
}
-(void)changeFrame
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:paperImage cache:NO];
[UIView commitAnimations];
}
私の懸念は、打撃が検出され、画像のアニメーションが実行されるたびに、この画像のコンテンツをどのように管理する必要があるかです.昨日からこのためにrndを行っていますが、今まで取り除くことができません.この問題を管理するためのコードがあれば、これ以上のことはありません。助けてくれたすべての人に感謝します。