小编Eri*_*ric的帖子

用另一个CALayer屏蔽CALayer

我正试图用CALayers制作甜甜圈.一个CALayer将是一个大圆圈,另一个将是一个位于其中心的较小圆圈,掩盖它.

大圆圈显示正常,但每当我打电话时circle.mask = circleMask;,视图显示为空.

这是我的代码:

AriDonut.h

#import <UIKit/UIKit.h>

@interface AriDonut : UIView
-(id)initWithRadius:(float)radius;
@end
Run Code Online (Sandbox Code Playgroud)

AriDonut.m

#import "AriDonut.h"
#import <QuartzCore/QuartzCore.h>

@implementation AriDonut

-(id)initWithRadius:(float)radius{
    self = [super initWithFrame:CGRectMake(0, 0, radius, radius)];
    if(self){

        //LARGE CIRCLE
        CALayer *circle = [CALayer layer];
        circle.bounds = CGRectMake(0, 0, radius, radius);
        circle.backgroundColor = [UIColor redColor].CGColor;
        circle.cornerRadius = radius/2;
        circle.position = CGPointMake(radius/2, radius/2);

        //SMALL CIRLCE
        CALayer *circleMask = [CALayer layer];
        circleMask.bounds = CGRectMake(0, 0, 10, 10);
        circleMask.cornerRadius = radius/2;
        circleMask.position = circle.position;

        //circle.mask = circleMask;

        [self.layer addSublayer:circle]; …
Run Code Online (Sandbox Code Playgroud)

core-animation calayer uiview ios

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

对NSIndexPaths数组进行排序

我有一个NSMutableArray包含NSIndexPath对象的东西,我想row按升序对它们进行排序.

什么是最短/最简单的方法?

这就是我尝试过的:

[self.selectedIndexPaths sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
    NSIndexPath *indexPath1 = obj1;
    NSIndexPath *indexPath2 = obj2;
    return [@(indexPath1.section) compare:@(indexPath2.section)];
}];
Run Code Online (Sandbox Code Playgroud)

nsmutablearray nsindexpath

12
推荐指数
3
解决办法
5149
查看次数

UICollectionViewCells中UIStackView的性能不佳

我在我的子类中使用UIStackView布局.我正在使用iOS SDK 9.2UILabelsUICollectionViewCell

如果我text在出列标签时不更新标签,则集合视图的滚动是平滑的.但是,如果我在将它们text出列时更新它们,则滚动速度非常慢.

我做了一个非常小的演示来显示问题,在设备(不是模拟器)上运行.您可以创建一个新的空项目并用以下内容替换ViewController.swift:

import UIKit

class ViewController: UIViewController {

    override func loadView() {
        view = UIView()

        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSize(width: 100, height: 200)
        let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
        collectionView.registerClass(Cell.self, forCellWithReuseIdentifier: "Cell")
        collectionView.translatesAutoresizingMaskIntoConstraints = false
        collectionView.dataSource = self
        view.addSubview(collectionView)

        let constraints = ["H:|-[collectionView]-|",
            "V:|[collectionView]|"
        ].flatMap { NSLayoutConstraint.constraintsWithVisualFormat($0, options: [], metrics: nil, views: ["collectionView": collectionView])
        }
        NSLayoutConstraint.activateConstraints(constraints)

    }
}

extension ViewController: UICollectionViewDataSource {
    func collectionView(collectionView: …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionviewcell uistackview

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

Objective-C中的iOS 10 Rich Media推送通知(媒体附件)

我想在iOS 10推送通知中添加媒体,尤其是图像和视频,但图像无法正常推送.如何在Objective-C中做到这一点?我的守则如下:

AppDelegate.h

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate,UNUserNotificationCenterDelegate>

@property (strong, nonatomic) UIWindow *window;
@end
Run Code Online (Sandbox Code Playgroud)

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if(SYSTEM_VERSION_LESS_THAN( @"10.0" )) {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    } else{
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
        {
            if( !error ) {
                [[UIApplication sharedApplication] registerForRemoteNotifications];
                // required to get the app to …
Run Code Online (Sandbox Code Playgroud)

objective-c ios ios10

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

使用NSProgress查找下载速度和剩余时间

根据我看到的文档NSProgress,-[NSProgress localizedAdditionalDescription]可以报​​告下载速度和剩余时间,例如:

1.61 GB的3.22 GB(2 KB /秒) - 剩余2分钟

但是,当我NSProgress将a 关联到a 时,我无法获得这些细节NSURLSessionDownloadTask.这是我的代码:

Downloader.h

@interface Downloader : NSObject
@property NSProgress *overallProgress;
-(void)startDownload;
@end
Run Code Online (Sandbox Code Playgroud)

Downloader.m

- (void)startDownload {

    self.overallProgress = [NSProgress progressWithTotalUnitCount:100];

    [self.overallProgress setKind:NSProgressKindFile];
    [self.overallProgress setUserInfoObject:NSProgressFileOperationKindKey forKey:NSProgressFileOperationKindDownloading];


    [self.overallProgress becomeCurrentWithPendingUnitCount:100];
    [self work1];
    [self.overallProgress resignCurrent];
}

- (void)work1 {

    NSProgress *firstTaskProgress = [NSProgress progressWithTotalUnitCount:1];
    [firstTaskProgress setKind:NSProgressKindFile];
    [firstTaskProgress setUserInfoObject:NSProgressFileOperationKindKey forKey:NSProgressFileOperationKindDownloading];

    NSURL *downloadURL = [NSURL URLWithString:@"http://ipv4.download.thinkbroadband.com/200MB.zip"];
    NSURL *destinationDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
    NSURL *destinationURL = …
Run Code Online (Sandbox Code Playgroud)

macos ios ios7 osx-mavericks nsprogress

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

scipy.io.wavfile给出"WavFileWarning:chunk not understand"错误

我正在尝试使用scipy读取.wav文件.我这样做:

from scipy.io import wavfile

filename = "myWavFile.wav"
print "Processing " + filename

samples = wavfile.read(filename)
Run Code Online (Sandbox Code Playgroud)

我得到了这个丑陋的错误:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/io/wavfile.py:121: WavFileWarning: chunk not understood
  warnings.warn("chunk not understood", WavFileWarning)
Traceback (most recent call last):
  File "fingerFooler.py", line 15, in <module>
    samples = wavfile.read(filename)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/io/wavfile.py", line 127, in read
    size = struct.unpack(fmt, data)[0]
struct.error: unpack requires a string argument of length 4
Run Code Online (Sandbox Code Playgroud)

我使用的是Python 2.6.6,numpy 1.6.2和scipy 0.11.0

是导致问题的wav文件.

有什么想法吗?这有什么不对?

python audio macos numpy scipy

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

自动布局:动画更改为NSLayoutConstraint的乘数

我有这个简单的观点:

- (void)viewDidLoad
{
    [super viewDidLoad];
    redBox = [[UIView alloc] init];
    [redBox setBackgroundColor:[UIColor redColor]];
    [redBox setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view addSubview:redBox];

    //H:
    widthConstraint = [NSLayoutConstraint constraintWithItem:redBox
                                                   attribute:NSLayoutAttributeWidth
                                                   relatedBy:NSLayoutRelationEqual
                                                      toItem:self.view
                                                   attribute:NSLayoutAttributeWidth
                                                  multiplier:0.5
                                                    constant:0.0];
    [self.view addConstraint:widthConstraint];

    //More constraints... 
}
Run Code Online (Sandbox Code Playgroud)

我想动画一下redBox宽度的增加.

我试过这个:

widthConstraint.constant = 100;

[UIView animateWithDuration:1
                 animations:^{
                     [self.view layoutIfNeeded];
                 }
 ];
Run Code Online (Sandbox Code Playgroud)

这会将视图的宽度增加100并对其进行动画处理,但我需要将其增加一个与其超视图宽度成比例的量.换句话说,我想设置widthConstraintS" multiplier0.8.

但是NSLayoutConstraintmultiplier是只读的!这是否意味着我widthConstraint每次想要对其进行动画修改时都必须删除,修改和重新添加,multiplier还是有更好的方法?

uikit ios autolayout nslayoutconstraint

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

仪器中的AutoLayout模板在哪里?

Apple建议使用Instruments中的Auto Layout模板来帮助调试Auto Layout问题.我在Xcode 5.0.2的模板中找不到它(我看到"空白","分配","泄漏",但没有自动布局).

这个模板在哪里?

xcode instruments ios autolayout

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

AsyncStorage 安全吗?

我想在我的 React Native 应用程序中保留用户的帐户凭据(即用户名和密码)。我应该使用AsyncStorage吗?

换句话说,我想知道是否以及如何AsyncStorage保护其内容。该文档是对沉默。

(我使用的是 RN v0.28)

react-native

8
推荐指数
3
解决办法
5151
查看次数

UIView:layoutSubviews vs initWithFrame

在子类化时UIView,我通常将所有初始化和布局代码放在其init方法中.但我被告知布局代码应该通过覆盖来完成layoutSuviews.SO上有一篇帖子解释了每个方法何时被调用,但我想知道如何在实践中使用它们.

我目前将所有代码都放在init方法中,如下所示:

MyLongView.m

- (id)initWithHorizontalPlates:(int)theNumberOfPlates
{
    self = [super initWithFrame:CGRectMake(0, 0, 768, 1024)];

    if (self) {
        // Initialization code
        _numberOfPlates = theNumberOfPlates;

        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.frame];
        [scrollView setContentSize:CGSizeMake(self.bounds.size.width* _numberOfPlates, self.bounds.size.height)];
        [self addSubview:scrollView];

        for(int i = 0; i < _numberOfPlates; i++){
            UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"a1greatnorth_normal_%d.jpg", i+1]];
            UIImageView *plateImage = [[UIImageView alloc] initWithImage:img];
            [scrollView addSubview:plateImage];
            plateImage.center = CGPointMake((plateImage.bounds.size.width/2) + plateImage.bounds.size.width*i, plateImage.bounds.size.height/2);
        }

    }
    return self;
} …
Run Code Online (Sandbox Code Playgroud)

uiscrollview uiview ios

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