小编Cor*_*les的帖子

如何使用CAKeyframeAnimation为CoreGraphics绘制形状的动画

我试图在UIView子类中为UIBeizerPath(在我的示例中为三角形)绘制动画.但是,整个子视图是动画而不是形状.

动画中是否有我遗漏的东西?

- (void)drawRect:(CGRect)rect {

   CAShapeLayer *drawLayer = [CAShapeLayer layer];

   drawLayer.frame           = CGRectMake(0, 0, 100, 100);
   drawLayer.strokeColor     = [UIColor greenColor].CGColor;
   drawLayer.lineWidth       = 4.0;

   [self.layer addSublayer:drawLayer];

   UIBezierPath *path = [UIBezierPath bezierPath];

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

  CGPoint center = [self convertPoint:self.center fromView:nil];

  [path applyTransform:CGAffineTransformMakeTranslation(center.x, center.y)];

  [[UIColor redColor] set];

  [path fill];

  [[UIColor blueColor] setStroke];

  path.lineWidth = 3.0f;

  [path stroke];

  CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

  pathAnimation.duration        = 4.0f;
  pathAnimation.path            = path.CGPath;
  pathAnimation.calculationMode = kCAAnimationLinear;

  [drawLayer addAnimation:pathAnimation forKey:@"position"];
}
Run Code Online (Sandbox Code Playgroud)

core-animation core-graphics uiview cakeyframeanimation

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

为什么AVAudioRecorder prepareToRecord失败?

我正在尝试设置一个记录用户音频输入(语音)的基本控制器.但是,AVAudioRecorder的prepareToRecord方法失败了,我无法弄清楚原因.我在我的app委托中设置了音频会话,当我实例化AVAudioRecorder实例时,我没有收到错误:

// App委托代码段

AVAudioSession* audioSession = [AVAudioSession sharedInstance];
NSError* audioSessionError   = nil;

[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
                  error: &audioSessionError];

  if (audioSessionError) {
    NSLog (@"Error setting audio category: %@", [audioSessionError localizedDescription]); 
} else {
  NSLog(@"No session errors for setting category");
}

[audioSession setActive:YES error:&audioSessionError];

if (audioSessionError) {
  NSLog (@"Error activating audio session: %@", [audioSessionError localizedDescription]); 
} else {
NSLog(@"no session errors for setActive");
}
Run Code Online (Sandbox Code Playgroud)

//在RECORDERCONTROLLER中查看DID LOAD

- (void)viewDidLoad {

self.navigationItem.title = [NSString stringWithFormat:@"%@", [[MyAppDelegate loadApplicationPlist] valueForKey:@"recorderViewTitle"]];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
                                                                                     target:self 
                                                                                     action:@selector(dismiss)]; …
Run Code Online (Sandbox Code Playgroud)

iphone avaudiorecorder

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

如何在swift中将void块传递给objc_setAssociatedObject

我正在尝试通过扩展程序向UIView添加tap手势支持.这很简单,使用Objective-C,但是当我尝试在运行时属性上设置void返回块时,我收到以下错误.

错误:类型'() - > Void'不符合协议'AnyObject'

这是计算属性:

var tapAction: (() -> Void)? {

    get {
        objc_getAssociatedObject(self, &AssociatedKeys.SNGLSActionHandlerTapBlockKey)
    }

    set {

        objc_setAssociatedObject(
            self,
            &AssociatedKeys.SNGLSActionHandlerTapBlockKey,
            newValue,
            UInt(OBJC_ASSOCIATION_COPY_NONATOMIC)
        )
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图将tapAction设置为a typealias,但仍然收到相同的错误.

ios swift

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

如何以编程方式定位mkmapregion以适合注释

我试图弄清楚如何以编程方式重新定位MKMap区域,以便我的注释(在地图加载时自动选择)将全部适合居中.

目前的结果:https://www.evernote.com/shard/s46/sh/7c7d2ed8-203c-4878-af8c-83ff77ad7b21/ce7786acdf66b0782fc689b72d1b67e7

期望的结果:https://www.evernote.com/shard/s46/sh/21fb0eab-d5c4-4e6d-b05b-322e7dcce8ab/ab816f2a24f11b9c9e15bf55ac648f72

我试图重新定位所有内容- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views但是没有用.有更好的方法吗?

//这里是viewWillAppear逻辑

[self.mapView removeAnnotations:self.mapView.annotations];

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

CLGeocodeCompletionHandler completionHandler = ^(NSArray *placemarks, NSError *error) {

if (error) {

  EPBLog(@"error finding placemarks: %@", [error localizedDescription]);

} else {

  if (placemarks) {

    [placemarks enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

      CLPlacemark *placemark = (CLPlacemark *)obj;

      if ([placemark.country isEqualToString:@"United States"]) {

        EPBAnnotation *annotation = [EPBAnnotation annotationWithCoordinate:placemark.location.coordinate];

        annotation.title    = self.locationObj.locationName;
        annotation.subtitle = self.locationObj.locationAddress;

        [self.mapView …
Run Code Online (Sandbox Code Playgroud)

mkmapview

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

为什么UIView动画闭包中的弱自引用会导致Swift中的编译错误

尝试在UIView动画闭包中使用弱引用时出现编译错误。根据其他教程和Apple的文档,这应该是有效的。

片段

                UIView.animateKeyframesWithDuration(0.35, delay: 0.5, options: UIViewKeyframeAnimationOptions.CalculationModeCubicPaced, animations:{ [weak self] in

                    UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0, animations:{

                        if let actualSelf = self {
                            actualSelf.noPlayListsView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.5, 1.5)
                        }
                    })

                    UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0, animations:{

                        if let actualSelf = self {
                            actualSelf.noPlayListsView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9)
                        }
                    })

                    UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0, animations:{

                        if let actualSelf = self {
                            actualSelf.noPlayListsView.transform = CGAffineTransformIdentity
                        }
                    })
                }, completion:nil)
Run Code Online (Sandbox Code Playgroud)

closures weak-references swift

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