小编Wal*_*chy的帖子

如何使用Core Graphics/iPhone绘制渐变线(淡入/淡出)?

我知道如何绘制一条简单的线条:

CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextMoveToPoint(context, x, y);
CGContextAddLineToPoint(context, x2, y2);
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)

我知道如何做一个渐变矩形,ig:

CGColorSpaceRef myColorspace=CGColorSpaceCreateDeviceRGB();
size_t num_locations = 2;
CGFloat locations[2] = { 1.0, 0.0 };
CGFloat components[8] = { 0.0, 0.0, 0.0, 1.0,    1.0, 1.0, 1.0, 1.0 };

CGGradientRef myGradient = CGGradientCreateWithColorComponents(myColorspace, components, locations, num_locations);

CGPoint myStartPoint, myEndPoint;
myStartPoint.x = 0.0;
myStartPoint.y = 0.0;
myEndPoint.x = 0.0;
myEndPoint.y = 10.0;
CGContextDrawLinearGradient (context, myGradient, myStartPoint, myEndPoint, 0);
Run Code Online (Sandbox Code Playgroud)

但是我怎么能画一条渐变的线条,ig从黑色渐变到白色(也可能在另一边渐渐变成黑色)?

iphone gradient core-graphics draw

24
推荐指数
4
解决办法
4万
查看次数

如何在iphone上编写实时准确的音频音序器?

我想在iphone上编写一个简单的音频音序器,但我无法获得准确的时序.最后几天我在iphone上尝试了所有可能的音频技术,从AudioServicesPlaySystemSound和AVAudioPlayer以及OpenAL到AudioQueues.

在我的最后一次尝试中,我尝试了使用openAL的CocosDenshion声音引擎,并允许将声音加载到多个缓冲区中,然后在需要时播放它们.这是基本代码:

在里面:

int channelGroups[1];
channelGroups[0] = 8;
soundEngine = [[CDSoundEngine alloc] init:channelGroups channelGroupTotal:1];

int i=0;
for(NSString *soundName in [NSArray arrayWithObjects:@"base1", @"snare1", @"hihat1", @"dit", @"snare", nil])
{
    [soundEngine loadBuffer:i fileName:soundName fileType:@"wav"];
    i++;
}

[NSTimer scheduledTimerWithTimeInterval:0.14 target:self selector:@selector(drumLoop:) userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)

在初始化中,我创建声音引擎,将一些声音加载到不同的缓冲区,然后使用NSTimer建立音序器循环.

音频循环:

- (void)drumLoop:(NSTimer *)timer
{
for(int track=0; track<4; track++)
{
    unsigned char note=pattern[track][step];
    if(note)
        [soundEngine playSound:note-1 channelGroupId:0 pitch:1.0f pan:.5 gain:1.0 loop:NO];
}

if(++step>=16)
    step=0;

}
Run Code Online (Sandbox Code Playgroud)

这就是它,它应该工作,但它的时机是不稳定和不稳定的.一旦发生其他事情(在视图中绘制),它就会失去同步.

据我所知,声音引擎和openAL缓冲区已加载(在初始化代码中),然后准备立即启动alSourcePlay(source);- 所以问题可能出在NSTimer?

现在appstore中有几十个声音序列器应用程序,它们具有准确的计时.当变焦和绘图完成时,Ig"idrum"在180 bpm时具有完美的稳定节拍.所以必须有一个解决方案.

有人有什么想法吗?

在此先感谢您的帮助!

最好的祝福,

Walchy


感谢您的回答.它让我更进一步,但不幸的是没有达到目的.这是我做的:

nextBeat=[[NSDate alloc] initWithTimeIntervalSinceNow:0.1]; …
Run Code Online (Sandbox Code Playgroud)

iphone audio timing openal core-audio

23
推荐指数
3
解决办法
1万
查看次数

如何使用AVAssetWriter编写带视频和音频的电影?

我想导出一部电影,AVAssetWriter但无法弄清楚如何同步包含视频和音频轨道.仅导出视频工作正常,但是当我添加音频时,生成的电影如下所示:

首先,我看到视频(没有音频),然后视频冻结(显示最后一个图像帧直到结束),几秒钟后我听到音频.

我尝试了一些事情CMSampleBufferSetOutputPresentationTimeStamp(CMSampleBufferGetPresentationTimeStamp从当前减去第一个)用于音频,但这一切都不起作用,我认为这不是正确的方向,因为源电影中的视频和音频应该是同步的. ..

我的设置简单:我创建一个AVAssetReader和2 AVAssetReaderTrackOutput(一个用于视频,一个用于音频)并将它们添加到AVAssetReader,然后我创建一个AVAssetWriter和2 AVAssetWriterInput(视频和音频)并将它们添加到AVAssetWriter...我开始一切:

[assetReader startReading];
[assetWriter startWriting];
[assetWriter startSessionAtSourceTime:kCMTimeZero];
Run Code Online (Sandbox Code Playgroud)

然后我运行2个队列来做样本缓冲区的东西:

dispatch_queue_t queueVideo=dispatch_queue_create("assetVideoWriterQueue", NULL);
[assetWriterVideoInput requestMediaDataWhenReadyOnQueue:queueVideo usingBlock:^
{
     while([assetWriterVideoInput isReadyForMoreMediaData])
     {
         CMSampleBufferRef sampleBuffer=[assetReaderVideoOutput copyNextSampleBuffer];
         if(sampleBuffer)
         {
             [assetWriterVideoInput appendSampleBuffer:sampleBuffer];
             CFRelease(sampleBuffer);
         } else
         {
             [assetWriterVideoInput markAsFinished];
             dispatch_release(queueVideo);
             videoFinished=YES;
             break;
         }
     }
}];

dispatch_queue_t queueAudio=dispatch_queue_create("assetAudioWriterQueue", NULL);
[assetWriterAudioInput requestMediaDataWhenReadyOnQueue:queueAudio usingBlock:^
{
    while([assetWriterAudioInput isReadyForMoreMediaData])
    {
        CMSampleBufferRef sampleBuffer=[assetReaderAudioOutput copyNextSampleBuffer];
        if(sampleBuffer)
        {
            [assetWriterAudioInput appendSampleBuffer:sampleBuffer];
            CFRelease(sampleBuffer);
        } else
        { …
Run Code Online (Sandbox Code Playgroud)

iphone audio video export avassetwriter

19
推荐指数
2
解决办法
1万
查看次数

如何知道用户何时触摸上一个StoreKit警报的"确定"按钮"谢谢.您的购买成功"?

我在游戏中集成了"In App Purchase",让用户解锁更多关卡.一切正常,但我最后一次提醒"谢谢你.你的购买成功了.[确定]".我的程序得知在最后一次警报弹出之前交易已成功完成,因此我的游戏再次开始运行 - 然后警报响起,使用户烦恼.我想等待我的游戏运行,直到用户触摸"确定"按钮,但由于它是来自StoreKit的警报,我不知道何时发生这种情况或者我是如何抓住它的.

我不想在警报下面创建另一个对话框(这次是我自己的,因此在我的控制之下),只是要求再次触摸"OK" - 这将是一个糟糕的用户体验.

有人有什么想法吗?

iphone in-app-purchase

7
推荐指数
1
解决办法
614
查看次数

是否可以在AVAssetExport上使用AVAssetExportPresetMediumQuality和AVAssetExportPresetHighestQuality之间的质量?

我正在使用AVAssetExportSession从我的iOS应用程序中导出视频,如下所示:

AVAssetExportSession *exportSession=[AVAssetExportSession exportSessionWithAsset:composition presetName:AVAssetExportPresetMediumQuality];
Run Code Online (Sandbox Code Playgroud)

我想上传导出的视频,因此大小很重要.问题是:中等质量是一个真正糟糕的质量,AVAssetExportPresetHighestQuality很好,但比中等质量大约5倍.

那么,有没有办法创建一个质量介于两者之间的视频,比方说大小是2倍?

这有可能AVAssetExportSession吗?

如果没有,是否可以使用AVAssetWriter?

提前致谢,

最好的祝福,

Walchy

iphone export ios4 avassetwriter

6
推荐指数
1
解决办法
2327
查看次数