小编hpi*_*que的帖子

旋转期间UIScrollView的contentOffset

我要手动更新contentOffsetUIScrollView过程中旋转的变化.滚动视图填充屏幕,具有灵活的宽度和灵活的高度.

我目前正在尝试更新contentOffset willRotateToInterfaceOrientation,如下所示:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [Utils logPoint:myScrollView.contentOffset tag:@"initial"];
    myScrollView.contentOffset = CGPointMake(modifiedX, modifiedY);
    [Utils logPoint:myScrollView.contentOffset tag:@"modified"];
}

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [Utils logPoint:myScrollView.contentOffset tag:@"final"];
}
Run Code Online (Sandbox Code Playgroud)

但是,最终值不是修改后的值,它似乎受到它的影响,但对我来说并不明显.

这些是我得到的一些结果:

initial: (146.000000;-266.000000)
modified: (81.000000;-108.000000)
final: (59.000000;-0.000000)

initial: (146.000000;-266.000000)
modified: (500.000000;500.000000)
final: (59.000000;500.000000)

initial: (146.000000;-266.000000)
modified: (-500.000000;-500.000000)
final: (-0.000000;-0.000000)
Run Code Online (Sandbox Code Playgroud)

如何在轮换期间更新滚动视图的contentOffset?

iphone rotation uiscrollview ipad

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

iPhone中的设备专用资源

根据iOS参考库:

在iOS 4.0及更高版本中,可以将各个资源文件标记为仅在特定类型的设备上可用.

这是否意味着如果您要为3.X设备创建通用应用程序,特别是3.2 iPad,则不能将设备特定资源用于~ipad~iphone后缀?

如果是这样,这是处理特定于设备的资源的正确方法吗?

UIImage* anImage;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    anImage = [UIImage imageNamed:@"MyImage-iPad.png"];
} else {
    anImage = [UIImage imageNamed:@"MyImage-iPhone.png"];
}  
Run Code Online (Sandbox Code Playgroud)

我应该知道的任何其他考虑因素?

iphone resources universal-binary ipad ios

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

使用CAAnimation实现CATransition推送

如何在iOS中实现子类的kCATransitionPush使用CAAnimation

CAAnimation *animation;
// How do you create an animation that does the same than:
// CATransition *animation = [CATransition animation];
// [animation setType:kCATransitionPush];        
[self.view.layer addAnimation:animation forKey:nil];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];        
[self.view addSubview:change];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

我知道可以使用UIView动画,但是如果我可以实现从头开始的转换,它将有助于我更好地理解核心动画.kCATransitionPush

iphone core-animation catransition caanimation ios

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

在iOS中使用ARC进行dealloc的单元测试

我想为一个dealloc方法编写iOS单元测试,该方法(基本上)将对象作为另一个对象的委托删除.

- (void) dealloc {
    someObject.delegate = nil;
}
Run Code Online (Sandbox Code Playgroud)

但是,dealloc在使用ARC时我无法直接呼叫.编写单元测试的最佳方法是什么?

unit-testing objective-c ios automatic-ref-counting

6
推荐指数
2
解决办法
2481
查看次数

为什么公共标题会生成多个产品包?

归档我当前的iOS项目时,我遇到了多个产品包问题.

基本上,当Xcode无法将您的项目识别为单个产品包时,就会发生这种情况,因此无法将其呈现为iOS App Archive,这是您提交给App Store的内容.

就我而言,解决方法 是删除一些引用的静态库的所有Public头文件(将它们更改为Project头文件).

这很糟糕,因为这些标题是出于某种原因而公开的.

为什么这有必要?这是一个Xcode错误还是我错过了什么?为什么有些静态库需要这个,有些则不需要?

最后,还有另一种解决此问题的方法,不需要更改标题可见性吗?

iphone static-libraries ios xcode4

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

显示NSSavePanel时超时

NSSavePanel应用程序处于后台显示一段时间时,我收到以下错误:

RVS:__54-[NSRemoteSavePanel _runOrderingOperationWithContext:]_block_invoke_0319 : Timeout occured while waiting for the window
Remote Window Controller requested NSRequestRetryActivateSharedwindow...
Run Code Online (Sandbox Code Playgroud)

此外,面板不会出现并runModal返回NSFileHandlingPanelCancelButton.

该应用程序是沙盒.这是创建面板的代码:

NSSavePanel *panel = [NSSavePanel savePanel];
NSInteger result = [panel runModal];
if (result == NSFileHandlingPanelOKButton)
{
    // Do something
}
Run Code Online (Sandbox Code Playgroud)

可能是什么问题?

如果应用程序位于前台,则会显示面板而不会出现任何错误.

macos cocoa nssavepanel

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

在Mac应用程序中导出NSDocument

如何NSDocument以一种格式将另一种格式导出为另NSDocument一种格式?

我想在我的基于文档的应用程序中实现典型的导出选项.我不确定我应该在哪里放置格式转换代码,以及Cocoa已经提供的内容.

macos cocoa nsdocument

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

基于iOS版本的条件单元测试

我的单元测试套件包含一些仅适用于最新iOS版本的测试用例.预计,在较旧的iOS版本上运行套件时,这些测试会失败.

是否有标准方法来指示这些测试用例应仅在特定的iOS版本上运行?

我想到的一个选择:

- (void) testSomethingThatOnlyWorksOniOS7
{
    const BOOL iOS7OrHigher = floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1;
    if (!iOS7OrHigher) return;

    // Actual test goes here
}
Run Code Online (Sandbox Code Playgroud)

或者,我可以告诉SenTestCase您动态跳过某些测试吗?

unit-testing objective-c ocunit ios sentestingkit

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

使用UISearchBar时UITableView contentSize错误

UITableView报告contentSize使用a时报告的结果大于预期UISearchBar.对于零单元,预期的内容高度将为零.相反,以下代码在运行iOS 7的iPhone 4英寸中输出612.

@implementation HPViewController {
    UITableView *_tableView;
    UISearchBar *_searchBar;
    UISearchDisplayController *_searchController;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:_tableView];

    _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

    _searchController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
    _searchController.delegate = self;
    _searchController.searchResultsDataSource = self;
    _tableView.tableHeaderView = _searchBar;
}

- (void)viewDidLayoutSubviews
{
    CGSize contentSize = _tableView.contentSize;
    NSLog(@"%f", contentSize.height); // 612.000000
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 0; }
- …
Run Code Online (Sandbox Code Playgroud)

uitableview uisearchbar ios ios7

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

应用程序中的iOS恢复购买收据

以下摘录来自Apple文档,如何在iOS 7中恢复应用程序.他们说您可以存储收据并稍后查看用户已购买的内容,或者您​​可以刷新App Receipt.我的问题是:

1)是否有一个应用程序收据或有多个单一收据?

2)存储这些收据更有意义,而不是直接存储用户已经购买的功能

3)我如何检查从刷新中获得的收据?到目前为止,我所有试图解析它的尝试都失败了.

4)是否有任何框架具有很多功能(在iCloud上保存收据/购买的产品,使购买更容易,处理下载,处理各种连接问题等)?甚至可能支持远程服务器(和验证).

我希望有人能提供帮助!:)


刷新应用程序收据

创建收据刷新请求,设置委托,然后启动请求.该请求支持在测试期间以各种状态获取收据的可选属性,例如过期收据 - 有关详细信息,请参阅SKReceiptRefreshRequest的initWithReceiptProperties:方法的值.

request = [[SKReceiptRefreshRequest alloc] init];
request.delegate = self;
[request start];
Run Code Online (Sandbox Code Playgroud)

收据刷新后,检查并交付任何已添加的产品.

storekit in-app-purchase ios

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