小编eri*_*ell的帖子

以编程方式更改UITextField键盘类型

是否可以以编程方式更改uitextfield的键盘类型,以便这样的事情可能:

if(user is prompted for numeric input only)
    [textField setKeyboardType: @"Number Pad"];

if(user is prompted for alphanumeric input)
    [textField setKeyboardType: @"Default"];
Run Code Online (Sandbox Code Playgroud)

iphone uitextfield uikeyboard ios

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

使用CALayer路径的CABasicAnimation不会设置动画

我正在尝试动画CALayer从正常角落到圆角的过渡.我只想绕过顶角,所以我使用的是UIBezierPath.这是代码:

UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;

UIBezierPath* newPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(8.0f, 8.0f)];
UIBezierPath* oldPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(0.0f, 0.0f)];

CAShapeLayer* layer = [CAShapeLayer layer];
layer.frame = self.bounds;
layer.path = oldPath.CGPath;

self.layer.mask = layer;

CABasicAnimation* a = [CABasicAnimation animationWithKeyPath:@"path"];
[a setDuration:0.4f];
[a setFromValue:(id)layer.path];
[a setToValue:(id)newPath.CGPath];

layer.path = newPath.CGPath;
[layer addAnimation:a forKey:@"path"];
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时,角落是圆形的,但是没有动画 - 它会立即发生.我在这里看到了一些类似的问题,但它们并没有解决我的问题.

iPhone CALayer动画

动画CALayer的shadowPath属性

我敢肯定,我只是做了一件小问题导致了这个问题,但对于我的生活,我无法理解.

解:

- (void)roundCornersAnimated:(BOOL)animated {
    UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;

    UIBezierPath* newPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(8.0f, 8.0f)];
    UIBezierPath* …
Run Code Online (Sandbox Code Playgroud)

core-animation calayer cabasicanimation cgpath uibezierpath

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

每次发布UIScrollView时都会发生内存泄漏

在我的应用程序中,我有一个滚动视图和四个表视图.每次拖动然后释放,我都会得到48字节的泄漏.这确实加起来了.如您所见,两组泄漏都具有相同的来源.以前有人见过这样的泄漏吗?




编辑1:

当我点击泄漏旁边的箭头时,我得到了泄漏信息:

memory-leaks instruments uiscrollview ios

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

目标C,线程1程序接收信号SIGABRT

我正在尝试使用Interface Builder编译和运行Objective C应用程序的简单教程.我正在使用Xcode 4.0.2并在iOS(iPhone)4.3上进行模拟

http://www.switchonthecode.com/tutorials/creating-your-first-iphone-application-with-interface-builder

当我构建项目时,它构建正常但是一旦应用程序尝试运行它崩溃:

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"SimpleUIAppDelegate");
    [pool release];
    return retVal;
}
Run Code Online (Sandbox Code Playgroud)

我在第4行得到错误:int retVal = UI ...线程1:程序接收信号"SIGABRT".

如果为了清楚起见需要发布该项目的其他文件,我可以这样做.

谢谢!

编辑:

SimpleUIViewController.h:

#import <UIKit/UIKit.h>

@interface SimpleUIViewController : UIViewController <UITextFieldDelegate> {
    UITextField *textInput;
    UILabel *label;
    NSString *name;
}

@property (nonatomic, retain) IBOutlet UITextField *textInput;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *name;

- (IBAction)changeGreeting:(id)sender;

@end
Run Code Online (Sandbox Code Playgroud)

SimpleUIViewController.m:

#import "SimpleUIViewController.h"

@implementation SimpleUIViewController

@synthesize …
Run Code Online (Sandbox Code Playgroud)

objective-c xib sigabrt ios xcode4

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

有没有实用的方法来压缩NSData?

我没有看到关于该主题的任何文档,但这并不意味着它不存在.

data-compression nsdata ios

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

NSURL isFileURL始终返回NO

有人可以向我解释为什么以下代码:

NSString* filePathString = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

NSLog(@"%i", [[NSURL URLWithString:filePathString] isFileURL]);
NSLog(@"%@", filePathString);
Run Code Online (Sandbox Code Playgroud)

输出:

0

"在/ var /移动/应用/ 28ADFC19-874C-4304-94B5-F6441CAE9FAD /文档"

这意味着此网址不是文件网址.显然,它是.


背景:

我正在尝试使用AVCaptureMovieFileOutput将电影录制内容写入文件,但我提供的文件网址提供错误:

*由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'* - [AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - 无法记录到URL/var/mobile/Applications/28ADFC19-874C-4304-94B5-F6441CAE9FAD/Documents/media/CrKNjNhe9so2LRnD9iHK .mov因为它不是文件URL.

对我来说,这看起来像一个文件URL,就像原始示例一样.是什么赋予了?

filesystems nsurl nsfilemanager ios avcapturemoviefileoutput

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

CLLocationManager响应

我有一个应用程序,围绕设备的GPS和来自它的信息.重要的是,位置数据必须准确并且是最新的.我知道该设备受到GPS和GPS限制的限制,但我想知道我是否可以采取任何措施来调整/改善iPhone GPS的性能,特别是在速度区域.由于位置更新滞后于设备实时位置约3-5秒,因此位置管理器报告的速度也远远落后于实时值.就我而言,这太长了.我知道可能没有什么我可以做的,但有没有人在提高iPhone GPS的响应能力方面有任何成功?每一点都有所作为.

编辑1:

正如Apple建议的那样,我的位置管理器位于单件类中.

在SingletonDataController.m中:

static CLLocationManager* locationManager;
locationManager = [CLLocationManager new];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.headingFilter = kCLHeadingFilterNone;

if(([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) || ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateFull)) {
    locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
} else {
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}

[sharedSingleton setLocationManager:locationManager];
[locationManager release];
Run Code Online (Sandbox Code Playgroud)

在MapView.m内部(实际使用位置管理器):

- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {
    //setup
    [SingletonDataController sharedSingleton].locationManager.delegate = self;
    //more setup
}

- (void)batteryChanged {
    if(([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) || ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateFull)) {
        [SingletonDataController sharedSingleton].locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
    } else { …
Run Code Online (Sandbox Code Playgroud)

performance gps core-location cllocationmanager ios

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

同时CCActions Cocos2d

是否可以同时在精灵上运行多个ccactions?例如,如果我有一个CCFadeIn,一个CCScaleTo和一个CCRotateBy,都具有相同的持续时间,我可以同时在精灵上运行所有三个吗?我发现的唯一远程关闭的东西是CCSequence,这不是我想要的.谢谢!

cocos2d-iphone ios

10
推荐指数
2
解决办法
6064
查看次数

重新排序UIView子视图

在我的应用程序中,我正在尝试将子视图添加到前面,然后将其放回到其原始图层位置.代码应该非常简单:

要将子视图放在前面(在我的自定义UIView类中):

[self.superview bringSubviewToFront:self];
Run Code Online (Sandbox Code Playgroud)

简单.我将原始z位置存储在一个名为的实例变量中,你猜对了zPosition.所以,前面的行-bringSubviewToFront:是:

zPosition = [self.superview.subviews indexOfObject:self];
Run Code Online (Sandbox Code Playgroud)

所以,我用来将子视图放在前面的所有代码都是:

zPosition = [self.superview.subviews indexOfObject:self];
[self.superview bringSubviewToFront:self];
Run Code Online (Sandbox Code Playgroud)

这应该是正常的.问题是当我尝试将子视图放回原位时.我只是这样做:

[self.superview exchangeSubviewAtIndex:zPosition withSubviewAtIndex:
    [self.superview.subviews indexOfObject:self]];
Run Code Online (Sandbox Code Playgroud)

使用此代码,如果我有两个子视图,则会发生以下情况:

假设我有视图A和视图B.视图A在视图B上方.我点击视图B,它来到前面.我再次点击视图B(它应该回到原来的位置),没有任何反应,所以它现在在视图A上.如果我现在点击视图A,它会到达前面,但是当我再次点击它时(所以它应该回到原来的z位置:在视图B)下面,它的所有兄弟视图都消失了!

有谁看到可能导致这个问题的原因?

layer uiview ios subviews

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

TensorFlow tf.reshape Fortran订单(如numpy)

TensorFlow是否提供了一种重塑Fortran中的张量的方法(列主要顺序?NumPy允许:

a = ...
np.reshape(a, (32, 32, 3), order='F')
Run Code Online (Sandbox Code Playgroud)

我正在尝试将CIFAR图像重塑为32x32x3(来自形状为3072x1的矢量),但我得到的图像看起来像这样:

示例CIFAR图像

在Numpy中使用Fortran命令解决了这个问题,但我需要在TensorFlow中做同样的事情.

编辑: 我现在意识到我可以通过重新整形到3x32x32然后转置输出来获得正确的输出.我仍然有点惊讶的是,TF不提供开箱即用的主要列主要顺序重塑.

python numpy reshape tensorflow

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