小编xar*_*rly的帖子

用简短的方法创建CGRect - swift

当我在Objective-c中创建CGRect并且我不想设置每个值时,我以这种方式创建:

 (CGRect){CGPointMake(0, 0), [UIScreen mainScreen].bounds.size}
Run Code Online (Sandbox Code Playgroud)

你知道swift中的类似方式吗?

cgrect swift

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

保留文件夹结构Cocoa Pods

我用本教程创建了一个简单的私有pod:http://pablin.org/2013/05/18/cocoapods-for-internal-libraries/

事实上,我的回购只有一组课程

一切都好,我可以完美地安装我的吊舱.唯一的问题是所有文件都安装在主文件夹内,因此它不保留文件夹结构.

我有这个文件夹结构,名为:myRepository的存储库

 Classes 
 |
 ------ foo.h and foo.m
 ------ Controller Layer
        |
        ----------- foo2.h and foo2.m
 ------ ViewLayer
        |
        ----------- foo3.h and foo3.m
Run Code Online (Sandbox Code Playgroud)

所有文件都复制到名为myRepository的文件夹中.

这是我的podspec:

Pod::Spec.new do |s|

  s.name         = "fooClasses"
  s.version      = "0.0.1"
  s.summary      = "Common clases of foo"

  s.homepage     = "http://foo.com"

  s.license      = 'BSD'
  s.license      = { :type => 'Foo License', :file => 'LICENSE.txt' }

  s.author       = { "me" => "me@me.com" }

  s.platform     = :ios, '7.0'

  s.source       = { :git => "https://github.com/myRepository.git", :tag …
Run Code Online (Sandbox Code Playgroud)

objective-c ios cocoapods

14
推荐指数
1
解决办法
6459
查看次数

WKWebView与本地文件

我正在使用本地文件测试WKWebView,该文件在模拟器中工作,但它在设备中不起作用

 @interface EDPresentationViewController ()<WKNavigationDelegate,WKScriptMessageHandler>


     @property(nonatomic,strong)WKWebView *webView;

     @property(nonatomic,strong)EDPresentationController *presentationController;

 @end


@implementation EDPresentationViewController

-(void)viewDidLoad
{
    [super viewDidLoad];

    self.presentationController = [[EDPresentationController alloc]init];

    WKWebViewConfiguration *webConfiguration = [[WKWebViewConfiguration alloc]init];
    self.webView = [[WKWebView alloc]initWithFrame:self.view.frame configuration:webConfiguration];

    NSURL *presentationFolder = [self.presentationController url];
    NSURLRequest *request = [NSURLRequest requestWithURL:presentationFolder];

    [self.webView loadRequest:request];
}
Run Code Online (Sandbox Code Playgroud)

我从以下网址授予网址:

    NSURL *presentationFolder = [self.presentationController url];
Run Code Online (Sandbox Code Playgroud)

没问题,因为我用UIWebview测试了相同的代码并且有效!

我总是得到同样的错误:

Could not create a sandbox extension for '/'
Run Code Online (Sandbox Code Playgroud)

这不起作用,我想它可以在Objective-C中工作,就像在swift中一样

iOS Webkit不在设备上工作,但在swift的模拟器上运行

任何想法将不胜感激,谢谢


更新2-12-2014

我发现这可能是iOS 8.1中的一个错误,可能会在8.2中修复

https://devforums.apple.com/thread/247777?start=25&tstart=0

我已经测试过将文件移动到临时文件夹,但我没有收到任何错误,但webView只是空的.

我用UIWebView测试了相同的代码(临时文件夹),工作正常!

另外,我试过这个:

/sf/answers/1823791931/

我可以发现,这是有效的,因为CSS和javascript嵌入在html中.

objective-c ios wkwebview

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

在Xcode 4中删除团队

我想删除Xcode(设备部分)中出现的团队.

我已经删除了分配给该团队的项目,我已经删除了分配给该团队的配置文件,我重新启动了Xcode.

但是团队还在那里(设备部分).

任何的想法?

ios xcode4

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

使用MPMoviePlayerViewController进行UIViewControllerAnimatedTransitioning

我正在尝试自定义演示动画,但VC是一个MPMoviePlayerViewController.我正在学习本教程:

当我出席时MPMoviePlayerViewController,一切都是对的.

但是当我解雇它时,只需要方法:

 - (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
Run Code Online (Sandbox Code Playgroud)

不叫,我做错了什么?

这是代码:

- (IBAction)playButtonTouchedIn:(id)sender {

    NSURL *url = [[NSBundle mainBundle]URLForResource:@"Learn to speak Spanish quickly with funny videos on youtube" withExtension:@"mp4"];

    MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
    player.transitioningDelegate = self;
    player.modalTransitionStyle = UIModalPresentationCustom;
    [player.moviePlayer setShouldAutoplay:NO];
    player.moviePlayer.controlStyle = MPMovieControlStyleNone;
    [self presentViewController:player animated:YES completion:^{
        [player.moviePlayer play];
        player.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    }];
}
Run Code Online (Sandbox Code Playgroud)

UIViewControllerTransitioningDelegate方法:

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:    (UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source
{
    self.presenting = YES;
    return self;
}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController …
Run Code Online (Sandbox Code Playgroud)

uiviewanimationtransition ios ios7

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

分支在私人吊舱中

我有一个私人吊舱,有两个分支掌握和开发.

我当前的项目正在使用该pod:

platform :ios, "7.0"

target "FooTarget" do

pod 'INCFoo'

end
Run Code Online (Sandbox Code Playgroud)

所以,目前我正在使用大师.我想使用开发分支.我尝试过:

platform :ios, "7.0"

target "FooTarget" do

pod 'INCFoo', :branch => 'develop'

end
Run Code Online (Sandbox Code Playgroud)

但我得到:[!]'INCFoo'的未知外部源参数:{branch =>"develop"}

最后它正在使用:

platform :ios, "7.0"

target "FooTarget" do

pod 'INCFoo', :git => 'git@github.com/INCFoo.git' :branch => 'develop'

end
Run Code Online (Sandbox Code Playgroud)

有没有办法在不添加存储库的情况下执行此操作?

谢谢

ios cocoapods

5
推荐指数
0
解决办法
657
查看次数

XCode 8签约产品

我刚刚更新到XCode 8,我正在使用一个旧项目(可能是在XCode 6或更早版本中创建)问题是(即使在模拟器中)XCode在步骤签名产品中至少停留了一半或一分钟.

使用XCode 7,设备中的应用程序启动非常快,并且没有任何签名产品阶段.

有没有办法让这个过程更快?

因为XCode包含新的功能来帮助您管理签名,我尝试在以下位置停用此功能:自动管理签名.我还有同样的问题.

我也试过XCode 8.1 Beta

任何的想法?

谢谢

code-signing xcode8

5
推荐指数
0
解决办法
728
查看次数

使用AFNetwotking的iOS 11错误的NSNumber双精度值

我想发送一个仅用两个小数位浮点数创建的NSNumber。

所以我要创建一个带有2个小数位数的NSNumberFormatter,但是它不尊重小数位数的数量。

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = NSNumberFormatterDecimalStyle;
    formatter.maximumFractionDigits = 2;
    formatter.roundingMode = NSNumberFormatterRoundUp;

    NSString *preformatedPreAuthPrice = [formatter stringFromNumber:@(4.44)]; 

    self.PreAuthPrice=[formatter numberFromString:preformatedPreAuthPrice];
Run Code Online (Sandbox Code Playgroud)

当我打印NSNumber的类型时,它是一个两倍

    p strcmp([(NSNumber *)[dictionary objectForKey:@"PreAuthPrice"] objCType], @encode(double))
(int) $1 = 0 
Run Code Online (Sandbox Code Playgroud)

如果我得到了价值:

    po [self.PreAuthPrice doubleValue]
    4.4400000000000004
Run Code Online (Sandbox Code Playgroud)

即使我这样做:

    po [@(4.44) doubleValue]
    4.4400000000000004
Run Code Online (Sandbox Code Playgroud)

有趣的是,当我在iOS 10上发送此NSNumber(使用AFNetworking版本2.6,3和3.1.0)时,它发送了正确的值4.44。但是在iOS 11上它会发送4.4400000000000004

这是查尔斯捕获的:

iOS 10

   {
   "preAuthPrice": 4.44,
   }
Run Code Online (Sandbox Code Playgroud)

iOS 11

   {
   "preAuthPrice":  4.4400000000000004
   }
Run Code Online (Sandbox Code Playgroud)

我也在基础库的发行说明中找到了这一点:

NS编号

迅速将NSNumber桥接到数字类型现在统一限制了as的情况?无论NSNumber是如何创建的,都进行转换。如果不能将数字安全地表示为目标类型,则将NSNumbers转换为数字类型将返回nil。

这发生在任何人身上吗?可能与发行说明有关吗?在iOS 10中发送[self.PreAuthPrice stringValue],在iOS 11中发送[self.PreAuthPrice doubleValue]

我知道一个解决方案是将值作为字符串发送,并且在阅读后也知道:

为什么浮点数不正确?

为什么十进制数字不能完全用二进制表示?

我知道这可能是问题所在,但是为什么要使用iOS 10。

nsnumber afnetworking-2 afnetworking-3 ios10 ios11

5
推荐指数
0
解决办法
303
查看次数

带#define的常量字符串数组 - objective c

我需要一个常量的字符串数组.使用#define是个好主意?

例如:

#define rows [NSArray arrayWithObjects:  @"NameRowA",@"NameRowB",@"NameRowC", nil]


#define KEY_ROWA [columnas objectAtIndex:0]
#define KEY_ROWB [columnas objectAtIndex:1]
#define KEY_ROWC [columnas objectAtIndex:2]
Run Code Online (Sandbox Code Playgroud)

我需要访问字符串数组和该数组的元素.

我已经读过了,(我不知道是不是真的)用这种方式创建一个新的NSArray,当它被使用时,我想这个数组已经发布了,所以我认为这很好,因为你只使用那部分内存什么时候需要它.

objective-c ios

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

防止NSAttributedString中的换行符

我认为当你有一组不想要断线的单词时,这是一个常见的问题.

有时这些单词之间的字符是空格或连字符等.在我的情况下,它是一个点:)

这是我的文字50.0/80.0

最后,我使用尺寸标签并测量了特别需要的字符串空间:

UIFont *fontAwardNumber = [UIFont fontWithName:@"DIN-Bold" size:20];

NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
CGSize labelSize = (CGSize){customCell.awardValueLabel.bounds.size.width, FLT_MAX};
CGRect rectNeededForAwardNumber = [awardNumber boundingRectWithSize:labelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: fontAwardNumber} context:context];
if (rectNeededForAwardNumber.size.height > customCell.awardValueLabel.bounds.size.height) {
    //We need to add a breakline
    NSRange range = [awardNumber rangeOfString:@"/"];
    if (range.location != NSNotFound) {
        awardNumber = [awardNumber stringByReplacingCharactersInRange:range withString:@"/\n"];
    }
}
Run Code Online (Sandbox Code Playgroud)

我找到了其他解决方案,例如用空格或连字符代替不可破坏的字符:

防止部分NSAttributedString中的换行符

但我的问题更为笼统,NSAttributedString是否提供了将一组单词定义为不可破解的内容?或者,对于一般词汇,有没有更简单的方法呢?

nsattributedstring ios

3
推荐指数
1
解决办法
1483
查看次数

checkResourceIsReachableAndReturnError总是返回Domain = NSCocoaErrorDomain Code = 4"操作无法完成.(Cocoa error 4.)"

我正在尝试使用:NSURL类的checkResourceIsReachableAndReturnError

但我总是得到FALSE并且NSError显示:Domain = NSCocoaErrorDomain Code = 4"操作无法完成.(Cocoa error 4.)"

我用safary检查了URL并且它有效,任何想法?

nsurl ios

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

UIKeyboardFrameEndUserInfoKey返回错误的原点 - iOS7

当文本字段被键盘隐藏时,我在尝试从视图控制器移动根视图(使用scrollView)时遇到一些问题.此文本字段不在根目录中.

我的应用程序在iOS7中运行并且只有纵向模式,如果位置是底部主页按钮,我从UIKeyboardFrameEndUserInfoKey获取正确的值:

(CGRect)$ 2 = origin =(x = 0,y = 760)size =(width = 768,height = 264)

但如果该位置是Top home按钮,则从UIKeyboardFrameEndUserInfoKey获取错误的原点:

(CGRect)$ 3 = origin =(x = 0,y = 0)size =(width = 768,height = 264)

你有什么主意吗?

谢谢!

keyboard textfield ios ios7

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