小编Tom*_*ulc的帖子

如何在Xcode 5中关闭图标光泽效果

我正在制作应用程序,我试图关闭图标光泽效果.在早期的Xcode 4中,它可以通过打开"Prerenderred"复选框来关闭图标光泽效果.现在,当我想使用资产目录时,我必须编辑.plist文件.我做到了.我添加键Icon already includes gloss effects并设置为YES但效果仍在图标上.如何在新Xcode中正确禁用此效果?

先感谢您.

xcode icons ios xcode5

21
推荐指数
2
解决办法
7331
查看次数

如何检测滑动手势方向?

我需要检测我的滑动手势的方向,我有问题.手势正在工作,但我不知道如何检测方向....

swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(detectSwipe:)];
[swipeGesture setNumberOfTouchesRequired:1];
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp];
[appView addGestureRecognizer:swipeGesture];

-(void)detectSwipe:(UISwipeGestureRecognizer *)recognizer { 
switch (recognizer.direction) {
    case UISwipeGestureRecognizerDirectionUp:
        NSLog(@"smth1");
        break;


    case UISwipeGestureRecognizerDirectionDown:
        NSLog(@"smth2");
    default:
        break;
}
}
Run Code Online (Sandbox Code Playgroud)

它不起作用:/

objective-c gesture-recognition swipe ios uiswipegesturerecognizer

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

是Float,Double,Int是AnyObject吗?

我阅读了Swift的内联文档,我有点困惑.

1)Any是所有类型隐式符合的协议.

2)AnyObject是所有类隐式符合的协议.

3) ,,Int 是结构FloatDouble

这是一个示例代码:

import UIKit

func passAnyObject(param: AnyObject) {
    print(param)
}

class MyClass {}
struct MyStruct {}

let a: Int = 1
let b = 2.0
let c = NSObject()
let d = MyClass()
let e = MyStruct()

passAnyObject(a)
passAnyObject(b)
passAnyObject(c)
passAnyObject(d)
//passAnyObject(e) // Argument type 'MyStruct' does not conform to expected type 'AnyObject'


if a is AnyObject { // b, d, e is also AnyObject
    print("\(a.dynamicType) is AnyObject") …
Run Code Online (Sandbox Code Playgroud)

ios swift swift2

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

UICollectionView中具有自定义UICollectionViewLayout的节的标题

我正在研究UICollectionView自定义布局.在两天内我无法理解如何添加标题UICollectionView.我有一个非常简单的视图控制器(在自定义布局的故事板中创建):

class ACollectionViewController: UICollectionViewController {

    enum Identifiers: String {
        case CellIdentifier = "Cell"
        case HeaderIdentifier = "Header"
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        self.collectionView.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: Identifiers.HeaderIdentifier.rawValue)
    }

    // MARK: UICollectionViewDataSource
    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Identifiers.CellIdentifier.rawValue, forIndexPath: indexPath) as Cell
        cell.backgroundColor = UIColor.redColor() …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uicollectionviewlayout swift

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

iOS 8上的MPVolumeView动画

在iOS 8中存在问题或功能.当显示MPVolumeView时,它会被动画化,就像从0扩展到它的宽度一样.我该如何解决这个问题呢?在iOS 7上没有这样的问题.

objective-c ios mpvolumeview ios8

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

如何在Swift中创建通用的便利初始化程序?

我正在使用Swift中的泛型.我有NSManagedObject类的扩展,并希望创建初始化程序,它只适用于实现我定义的某些协议的类.现在我有类似下面的东西,但这不起作用,甚至没有编译.你能帮我把它搞定吗?

public extension NSManagedObject {
    public convenience init<Self: Nameable>(context: NSManagedObjectContext)     {
        let entity = NSEntityDescription.entityForName(Self.entityName(), inManagedObjectContext: context)!
        self.init(entity: entity, insertIntoManagedObjectContext: context)
    }
}

public protocol Nameable {
    static func entityName() -> String
}
Run Code Online (Sandbox Code Playgroud)

Xcode说:"函数签名中没有使用通用参数'Self'".

generics swift

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

我将图像上下颠倒,但如何将图像水平翻转

我从相机胶卷加载图像,但此图像是颠倒的.所以我写了旋转它的方法.

CGImageRef imageRef = [image CGImage];

float width = CGImageGetWidth(imageRef);
float height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
Byte *rawData = malloc(height * width * 4);
Byte bytesPerPixel = 4;
int bytesPerRow = bytesPerPixel * width;
Byte bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
int byteIndex = 0;
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);

Byte *rawData2 = malloc(height * width * 4);

for (int i = 0 ; i < width …
Run Code Online (Sandbox Code Playgroud)

objective-c rotation flip uiimage

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

如何从OCMock开始并检查是否调用了方法

我正在努力解决这个问题OCMock.我创建了简单的类MyClass.

@interface MyClass : NSObject
- (NSString *)simpleMethod;
@end

@implementation MyClass

- (NSString *)simpleMethod {
    [self method];
    return @"simple";
}

- (void)method {
    NSLog(@"ABC");
}

@end
Run Code Online (Sandbox Code Playgroud)

我想要检查的是method调用方法时simpleMethod是否调用了方法.现在我有以下代码,但它不起作用:

- (void)testMethodInvoked
{
    id mock = [OCMockObject mockForClass:[MyClass class]];
    [[mock stub] simpleMethod];

    SEL selector = NSSelectorFromString(@"method");
    [[mock expect] methodForSelector:selector];
    [mock verify];
}
Run Code Online (Sandbox Code Playgroud)

我该如何测试这个案例?我认为这很容易做到,但我不知道如何解决这个问题.

如何创建调用方法的mock和call simpleMethod方法method

当前日志:

<unknown>:0: error: -[OCMockTestTests testOne] : OCMockObject[MyClass]: expected method was not invoked: methodForSelector:@selector(method)
Run Code Online (Sandbox Code Playgroud)

tdd unit-testing objective-c ocmock ios

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

如何使用fstream在c ++中附加文件?

我尝试在 C++ 中附加文件。启动文件不存在。操作后,文件中只有一行而不是五行(此方法的 5 次调用)。看起来文件正在创建,接下来每个写操作文件都被清除并添加新字符串。

void storeUIDL(char *uidl) {
        fstream uidlFile(uidlFilename, fstream::app | fstream::ate);

        if (uidlFile.is_open()) {
        uidlFile << uidl;
        uidlFile.close();
    } else {
        cout << "Cannot open file";
    }
}
Run Code Online (Sandbox Code Playgroud)

我试过fstream::in ,fstream::out。如何在此文件中正确附加字符串?

先感谢您。

编辑:

这是更广泛的观点:

for (int i = 0; i < items; i++) {
    MailInfo info = mails[i];
    cout << "Downloading UIDL for email " << info.index << endl;

    char *uidl = new char[100];
    memset(uidl, 0, 100);
    uidl = servicePOP3.UIDL(info.index);
    if (uidl != NULL) {
        if …
Run Code Online (Sandbox Code Playgroud)

c++ fstream

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

NSRegularExpression无法找到捕获组匹配项

我正在尝试使用一个正则表达式模式解析字符串.

这是模式:

(\")(.+)(\")\s*(\{)
Run Code Online (Sandbox Code Playgroud)

这是要解析的文本:

"base" {
Run Code Online (Sandbox Code Playgroud)

我想找到这4个捕获组:

1. "
2. base
3. "
4. {
Run Code Online (Sandbox Code Playgroud)

我正在使用以下代码尝试捕获这些组

class func matchesInCapturingGroups(text: String, pattern: String) -> [String] {
    var results = [String]()

    let textRange = NSMakeRange(0, count(text))
    var index = 0

    if let matches = regexp(pattern)?.matchesInString(text, options: NSMatchingOptions.ReportCompletion, range: textRange) as? [NSTextCheckingResult] {
        for match in matches {
            // this match = <NSExtendedRegularExpressionCheckingResult: 0x7fac3b601fd0>{0, 8}{<NSRegularExpression: 0x7fac3b70b5b0> (")(.+)(")\s*(\{) 0x1}
            results.append(self.substring(text, range: match.range))
        }
    }

    return results
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,它只能找到一个范围(0, 8)等于的组:"base" {.所以它找到一个组,它是整个字符串而不是4个组. …

regex ios capturing-group nsregularexpression swift

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