小编sol*_*eil的帖子

如何从Xcode中删除MPAVController控制台日志

自从我上次更新XCode后,我在播放视频时收到了很多MPAVController日志,如下所示:

[MPAVController] Autoplay: Likely to keep up or full buffer: 0
[MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
[MPAVController] Autoplay: Disabling autoplay for pause
[MPAVController] Autoplay: Disabling autoplay
...
Run Code Online (Sandbox Code Playgroud)

它非常烦人并填满了控制台.我该如何关闭它们?

console xcode mpmovieplayercontroller ios

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

ios - 从当前比例缩放/缩放

下面的代码正确地捏合/缩放容器视图,但只有在它跳转到1.0的标度之后.如何修改它以使容器视图从其当前比例缩放?

UIPinchGestureRecognizer *twoFingerPinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];
[self.container addGestureRecognizer:twoFingerPinch];

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer 
{
    _scale = recognizer.scale;
    CGAffineTransform tr = CGAffineTransformScale(self.view.transform, _scale, _scale);
    self.container.transform = tr;
}
Run Code Online (Sandbox Code Playgroud)

gesture-recognition uiview uigesturerecognizer ios

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

UIScrollView - 告诉setContentOffset和手动滚动之间的区别

我有一个scrollview,每3秒自动前进到下一个"页面"(也使用页面控件).但是,一旦用户触摸滚动视图,我想停止自动前进.

我已经将scrollview子类化了.我可以在子类中检测touchesBegan,但是没有调用touchesMoved,所以我无法判断用户是否手动刷过了scrollview.我不能使用scrollviewDidScroll,因为当我在自动前进计时器触发时设置contentOffset时会调用它.

那么我检测触摸的其他选择是什么?为什么不在scrollview子类上调用touchesMoved?

uiscrollview touchesmoved touchesbegan ios

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

Xcode - 条件开发或生产模式

在搜索这个我只能找到其他语言的信息.我想知道编写条件语句的最佳实践,例如:

if (DEV_MODE){
    //do something
}else{
    //do the real stuff
}
Run Code Online (Sandbox Code Playgroud)

然后在某个全局文件中打开或关闭DEV_MODE,因此我只需将其更改为打开或关闭,而不是在多个位置更改代码.我有一些想法,但我正在寻找最佳方法的建议.

c objective-c ios

6
推荐指数
2
解决办法
3632
查看次数

如何在仅限肖像的应用程序中使用MPMovieViewController播放风景视频

我的应用程序支持的界面方向是纵向和上下颠倒.但是,播放视频时,我希望它能够播放全屏风景.目前使用此代码,即使设备旋转,它也只播放肖像:

[player.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self presentMoviePlayerViewControllerAnimated:player];
Run Code Online (Sandbox Code Playgroud)

如何强制它进入横向模式?

mpmovieplayercontroller uiinterfaceorientation ios

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

如何在UIScrollView上为zoomScale设置动画

我需要设置zoomScale回到1上一个UIScrollView,但我需要它来进行动画.我以为我可以使用CABasicAnimation这一点,但NSValue似乎并不具有"valueForFloat"或"valueForNSNumber",所以我不知道用什么animation.fromValue和animation.toValue为CABasicAnimation.有没有更好的方法来解决这个问题?

编辑:我需要添加什么才能工作?

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"zoomScale"];
        animation.duration = 2.3;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];        
        animation.fromValue = [NSNumber numberWithFloat:myScrollview.zoomScale];
        animation.toValue = [NSNumber numberWithFloat:1.0];

        [myScrollview.layer addAnimation:animation forKey:@"zoomScale"];
Run Code Online (Sandbox Code Playgroud)

uiscrollview cabasicanimation ios nsvalue

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

动画UIView的面具

我可以创建一个这样的面具:

CALayer *mask = [CALayer layer];
    mask.contents = (id)[[UIImage imageNamed:@"mask.png"] CGImage];
    mask.frame = CGRectMake(0, 0, 10, 10);
    self.content.layer.mask = mask;
Run Code Online (Sandbox Code Playgroud)

这将正确显示我的内容的左上角10个像素(因为mask.png只是一个黑色图像).但是,我想为蒙版设置动画以显示其余内容:

 [UIView animateWithDuration:3.0
                     animations:^{
                         mask.frame = self.content.bounds;
                     }
                     completion:^(BOOL finished){

                     }];
Run Code Online (Sandbox Code Playgroud)

问题是没有动画.整个内容立即显示.为什么会发生这种情况,我如何为蒙版设置动画,以便从左上方显示内容?

mask calayer uiview uiviewanimation ios

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

iOS - 导致空值的CoreData错误

当我第一次填充视图时,我这样做:

self.cats = [[DataManager sharedManager] getCatsFromCoreData]; //cats is an NSArray property (strong)
for (Cat* cat in self.cats)
    {
        CatThumbnailView *thumb = [CatThumbnailView catThumbnailView];
        thumb.cat = cat;

        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(thumbnailTapped:)];
        [thumb addGestureRecognizer:tap];
        [thumb setText:[cat.name uppercaseString]];

        ...


        [self.someScrollview addSubview:thumb];
        yPos += thumb.frame.size.height + spacing;
    }
Run Code Online (Sandbox Code Playgroud)

DataManager的get方法如下所示:

- (NSArray*)getCatsFromCoreData
{

    NSManagedObjectContext *context = [[CoreDataController sharedController] managedObjectContext];

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:[NSEntityDescription entityForName:@"Cats" inManagedObjectContext:context]];
    [request setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"order" ascending:YES]]];


    NSError *error = nil;
    NSArray *fetchedCats = …
Run Code Online (Sandbox Code Playgroud)

core-data fault uiview ios

6
推荐指数
2
解决办法
3232
查看次数

发射开始后更改CAEmitterLayer的CAEmitterCell属性

当我第一次设置发射器时,我可以这样做:

self.cell = [CAEmitterCell emitterCell];
self.cell.yAcceleration = 20;
...
self.emitter.emitterCells = [NSArray arrayWithObjects:self.cell,nil];
Run Code Online (Sandbox Code Playgroud)

但是说我创建了一个5秒后触发的计时器,我这样做:

- (void)timerFired
{
    self.cell.yAcceleration = -10;

}
Run Code Online (Sandbox Code Playgroud)

计时器触发,但CAEmitterCell的yAcceleration不会更改.或者至少屏幕上的粒子发射没有任何变化.如何让CAEmitterCell尊重我对其属性所做的更改?

ios particle-system caemitterlayer caemittercell

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

Swift - 在枚举数组中查找具有关联值的对象

我有这个枚举:

enum Animal {       
    case cat(CatModel)
    case dog(DogModel)
}
Run Code Online (Sandbox Code Playgroud)

还有一系列动物:

var animals: [Animal]
Run Code Online (Sandbox Code Playgroud)

我需要通过 Dog 没有的属性在该数组中找到 Cat 对象。litterBoxId例如。

let cat = animals.first(where: {$0.litterBoxId == 7})
Run Code Online (Sandbox Code Playgroud)

这当然有一个错误:

Value of type 'MyViewController.Animal' has no member 'litterBoxId'
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我也尝试过

($0 as CatModel).litterBoxId
Run Code Online (Sandbox Code Playgroud)

arrays search enums swift associated-value

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