我正在制作应用程序,我试图关闭图标光泽效果.在早期的Xcode 4中,它可以通过打开"Prerenderred"复选框来关闭图标光泽效果.现在,当我想使用资产目录时,我必须编辑.plist文件.我做到了.我添加键Icon already includes gloss effects并设置为YES但效果仍在图标上.如何在新Xcode中正确禁用此效果?
先感谢您.
我需要检测我的滑动手势的方向,我有问题.手势正在工作,但我不知道如何检测方向....
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
我阅读了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) 我正在研究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 8中存在问题或功能.当显示MPVolumeView时,它会被动画化,就像从0扩展到它的宽度一样.我该如何解决这个问题呢?在iOS 7上没有这样的问题.
我正在使用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'".
我从相机胶卷加载图像,但此图像是颠倒的.所以我写了旋转它的方法.
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) 我正在努力解决这个问题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) 我尝试在 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) 我正在尝试使用一个正则表达式模式解析字符串.
这是模式:
(\")(.+)(\")\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个组. …