小编bla*_*cos的帖子

如何在CALayer中绘制径向渐变?

我知道CAGradientLayer目前不支持径向渐变,只能选择kCAGradientLayerAxial.

我想要下面的东西:

在此输入图像描述

我一直在寻找这个问题,并发现有一种解决方法.但这些解释对我来说并不清楚.所以我想知道我是否可以使用径向渐变CAGradientLayer,如果是,那么如何做呢?

objective-c calayer ios quartz-core

26
推荐指数
3
解决办法
2万
查看次数

检测bezier路径内的水龙头

我有一个UIView,它作为子视图添加到我的视图控制器.我在这个观点上画了一条更好的路径.我的drawRect实现如下

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    UIBezierPath *bpath = [UIBezierPath bezierPath];

    [bpath moveToPoint:CGPointMake(50, 50)];
    [bpath addLineToPoint:CGPointMake(100, 50)];
    [bpath addLineToPoint:CGPointMake(100, 100)];
    [bpath addLineToPoint:CGPointMake(50, 100)];
    [bpath closePath];

    CGContextAddPath(context, bpath.CGPath);
    CGContextSetStrokeColorWithColor(context,[UIColor blackColor].CGColor);
    CGContextSetLineWidth(context, 2.5);
    CGContextStrokePath(context);
    UIColor *fillColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.5 alpha:0.7];
    [fillColor setFill];
    [bpath fill];
}
Run Code Online (Sandbox Code Playgroud)

我希望在这个bezier路径中检测tap,但不是在UIView内部和路径外部的点.例如,在这种情况下,如果我的触摸坐标是(10,10),则不应检测到它.我知道CGContextPathContainsPoint但是当触摸在路径内时它没有帮助.有没有办法检测bezier路径内的触摸事件?

core-graphics objective-c ios uibezierpath

11
推荐指数
3
解决办法
6884
查看次数

如何在ios中恢复音频?

Audioplayer用于播放5-10秒的音频文件.我的应用程序允许其他应用的背景音乐.在播放我的音频时,我正在停用其他音乐

 [[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
Run Code Online (Sandbox Code Playgroud)

完成音频后,我想播放已停用的音乐.

这可能在AVAudioPlayer&AVAudioSession?或者哪个框架支持这种恢复功能?

audio avfoundation ios ios7

10
推荐指数
1
解决办法
891
查看次数

使用CAGradientLayer定义渐变的角度

我正在尝试使用绘制角度渐变CaGradientLayer.我知道角度可以使用startPoint和定义endPoint.我可以为一些标准角度计算这些点,如0,90,180,360等.但我希望将这些点制定为任意角度.我曾尝试用一些三角函数计算它,但没有取得任何成功.任何人都可以给我任何方向如何计算任意角度的这些点?

gradient objective-c linear-gradients ios cagradientlayer

9
推荐指数
3
解决办法
7847
查看次数

使用closePath函数关闭贝塞尔曲线路径并手动关闭它有什么区别?

我正在尝试使用矩形UIBezierPath.我采用了两种不同的方法来绘制它.另外,我将笔画宽度增加到25像素.

第一种方法:使用closePath

UIBezierPath *bpath = [UIBezierPath bezierPath];

[bpath moveToPoint:CGPointMake(x, y)];
[bpath addLineToPoint:CGPointMake(x + w, y)];
[bpath addLineToPoint:CGPointMake(x + w, y + h)];
[bpath addLineToPoint:CGPointMake(x, y + h)];
[bpath closePath];
Run Code Online (Sandbox Code Playgroud)

输出:

使用closePath

第二种方法:手动关闭路径

UIBezierPath *bpath = [UIBezierPath bezierPath];

[bpath moveToPoint:CGPointMake(x, y)];
[bpath addLineToPoint:CGPointMake(x + w, y)];
[bpath addLineToPoint:CGPointMake(x + w, y + h)];
[bpath addLineToPoint:CGPointMake(x, y + h)];
[bpath addLineToPoint:CGPointMake(x, y)];
Run Code Online (Sandbox Code Playgroud)

输出:

手动关闭路径

closePath它的文档中说This method closes the current subpath by creating a line segment between the first and …

core-graphics ios uibezierpath

8
推荐指数
1
解决办法
1654
查看次数

使用AVMutableComposition合并视频的空白帧

这个问题之前已被多次询问,但没有任何帮助.我正在使用合并多个视频AVMutableComposition.合并视频后,我会在30%到40%的视频中出现空白帧.其他合并很好.我刚玩的组成直接使用AVPlayer作为AVPlayerItem.代码如下:

AVMutableComposition *mutableComposition = [AVMutableComposition composition];
    AVMutableCompositionTrack *videoCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo
                                                                                       preferredTrackID:kCMPersistentTrackID_Invalid];
    AVMutableCompositionTrack *audioCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeAudio
                                                                                       preferredTrackID:kCMPersistentTrackID_Invalid];

    NSMutableArray *instructions = [NSMutableArray new];
    CGSize size = CGSizeZero;

    CMTime time = kCMTimeZero;
    for (AVURLAsset *asset in assets)
    {
        AVAssetTrack *assetTrack;
        assetTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
        AVAssetTrack *audioAssetTrack = [asset tracksWithMediaType:AVMediaTypeAudio].firstObject;

        NSError *error;
        [videoCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, assetTrack.timeRange.duration )
                                       ofTrack:assetTrack
                                        atTime:time
                                         error:&error];


        if (error) {
            NSLog(@"asset url :: %@",assetTrack.asset);
            NSLog(@"Error - %@", error.debugDescription);
        }

        [audioCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, assetTrack.timeRange.duration)
                                       ofTrack:audioAssetTrack …
Run Code Online (Sandbox Code Playgroud)

video objective-c avfoundation ios avmutablecomposition

8
推荐指数
1
解决办法
1197
查看次数

如何为CAShapeLayer绘制圆点笔划图案?

我试图CAShapeLayer用破折号模式来描述这些路径.我使用lineDashPattern属性创建了许多破折号模式.但是这个属性并没有为strokes类型提供任何选项.我想成为我的破折号是圆点,如下图所示:

在此输入图像描述

我知道它可以实现,因为我在许多应用程序中看到过这一点.但我无法找到任何方法在CAShapeLayer库中实现它.所以我想知道如何获得这些圆点破折号模式?

core-graphics objective-c cashapelayer ios

7
推荐指数
2
解决办法
3040
查看次数

使用UIBezierPath动画绘制弧

我用以下方法画了一个圆弧:

- (void)drawRect:(CGRect)rect {
    UIBezierPath *stripePath = [UIBezierPath bezierPath];
    [arcColor set];
    [stripePath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:clockwise];
    stripePath.lineWidth = arcWidth;
    stripePath.lineCapStyle = kCGLineCapRound;
    stripePath.lineJoinStyle = kCGLineCapRound;
    [stripePath stroke];
}
Run Code Online (Sandbox Code Playgroud)

现在我想以角度为这个弧设置动画.

我正在尝试使用类似的东西:

angle = startAngle;
[UIView animateWithDuration:1
                      delay:0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     angle = endAngle;
                     [stripePath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:angle clockwise:clockwise];
                     [stripePath stroke];
}];
Run Code Online (Sandbox Code Playgroud)

但是,屏幕上没有显示动画.如何使用角度作为变化变量来设置弧的动画?谢谢.

core-animation ios

7
推荐指数
2
解决办法
2285
查看次数

使用AVMutableVideoComposition时AVMutableComposition冻结的奇怪行为

我正在尝试使用合并多个视频AVMutableComposition.我面临的问题是每当我尝试添加AVMutableVideoComposition任何指令时,我的播放都会在AVPlayer6秒的时间内冻结.

另一个有趣的事情是,如果我在使用相同的导出后在iPad的照片应用程序中播放它就可以正常播放videoComposition.那为什么它会AVPlayer在6秒内冻结?

码:

AVMutableComposition *mutableComposition = [AVMutableComposition composition];

    AVMutableCompositionTrack *videoCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo
                                                                                        preferredTrackID:kCMPersistentTrackID_Invalid];

    AVMutableCompositionTrack *audioCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeAudio
                                                                                       preferredTrackID:kCMPersistentTrackID_Invalid];

    for (AVURLAsset *asset in assets)
    {
            AVAssetTrack *assetTrack;
            assetTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
            AVAssetTrack *audioAssetTrack = [asset tracksWithMediaType:AVMediaTypeAudio].firstObject;


            NSError *error;
            [videoCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, assetTrack.timeRange.duration )
                                                   ofTrack:assetTrack
                                                    atTime:time
                                                     error:&error];

            if (error) {
                NSLog(@"asset url :: %@",assetTrack.asset);
                NSLog(@"Error1 - %@", error.debugDescription);
            }

            [audioCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAssetTrack.timeRange.duration)
                                               ofTrack:audioAssetTrack
                                                atTime:time
                                                 error:&error];

            if (error) {
                NSLog(@"Error2 - …
Run Code Online (Sandbox Code Playgroud)

video objective-c avfoundation ios avmutablecomposition

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

当AVQueuePlayer从资产跳到另一个时,烦人的延迟

我有一个AVQueuePlayer应该按顺序播放一个AVURLAsset表示一个连续视频的连续片段的数组.

每当一个片段结束而另一个片段开始时,就会有一个很小的小故障(帧保持约0.2秒,声音被静音)

我试着研究如何解决这个问题,但没有找到任何东西.我尝试用2来解决它,AVQueuePlayer并在每个片段结束前0.2秒左右切换.问题没有解决.

关于如何解决这个问题的任何想法?

注意:使用mp4 joiner软件将mp4片段连接在一起时,输出是一个平滑的视频,没有任何故障.

mpmovieplayercontroller avfoundation ios avqueueplayer swift

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

AVAssetExportSession导出太慢

我正在尝试导出AVMutableComposition使用AVAssetExportSession.

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mutableComposition presetName:AVAssetExportPresetHighestQuality];
    exporter.outputURL=url;
    exporter.outputFileType = AVFileTypeQuickTimeMovie;
    exporter.videoComposition = mainCompositionInst;
    exporter.shouldOptimizeForNetworkUse = YES;

    [exporter exportAsynchronouslyWithCompletionHandler:^
     {
         switch (exporter.status)
         {
             case AVAssetExportSessionStatusCompleted:
             {
                 NSLog(@"Video Merge SuccessFullt");
             }
                 break;
             case AVAssetExportSessionStatusFailed:
                 NSLog(@"Failed:%@", exporter.error.description);
                 break;
             case AVAssetExportSessionStatusCancelled:
                 NSLog(@"Canceled:%@", exporter.error);
                 break;
             case AVAssetExportSessionStatusExporting:
                 NSLog(@"Exporting!");
                 break;
             case AVAssetExportSessionStatusWaiting:
                 NSLog(@"Waiting");
                 break;
             default:
                 break;
         }
     }];
Run Code Online (Sandbox Code Playgroud)

但是出口即使是1分钟的视频也需要30秒左右,考虑到iPad内置摄像头应用程序需要不到2秒的时间.

此外,如果我videoComposition从导出器中删除,时间减少到7秒,这仍然是不好的,考虑到视频长度只有1分钟.那么,我想知道如何将出口时间减少到最低限度?

另外,我想知道,AVAssetExportSession一般需要这么多时间,还是只是我的情况?

更新:合并代码:

AVMutableComposition*mutableComposition = [AVMutableComposition composition];

AVMutableCompositionTrack *videoCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo
                                                                                   preferredTrackID:kCMPersistentTrackID_Invalid];

AVMutableCompositionTrack *audioCompositionTrack = …
Run Code Online (Sandbox Code Playgroud)

video objective-c avfoundation ios avassetexportsession

5
推荐指数
1
解决办法
2394
查看次数

如何使用UIBezierPath以一定角度绘制椭圆?

我正在使用以下UIBezierPath方法绘制椭圆:

UIBezierPath *bpath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, y, width, height)];
Run Code Online (Sandbox Code Playgroud)

这给了我类似下面的内容:

在此输入图像描述

但我想以如下角度绘制椭圆:

在此输入图像描述

我知道一个解决方案是旋转UIView.但我不能这样做,因为同一个视图包含其他bezier路径.所以我想知道是否有办法以一定的角度绘制这个椭圆?

core-graphics ellipse quartz-2d ios uibezierpath

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

如何在iOS中播放音频文件时显示进度条

我在服务器中有一个音频文件,所以我可以用url播放音频文件.下面是代码.如何在播放音频文件时显示进度条?

-(void)playselectedsong{
    AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:urlString]];
    [player play];
}
Run Code Online (Sandbox Code Playgroud)

iphone avfoundation audio-streaming avaudioplayer ios

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