小编Fog*_*ter的帖子

targetContentOffsetForProposedContentOffset:withScrollingVelocity,没有子类化UICollectionViewFlowLayout

我的应用程序中有一个非常简单的collectionView(只有一行方形缩略图).

我想拦截滚动,以便偏移始终在左侧留下完整的图像.此刻,它滚动到任何地方,并将留下截止的图像.

无论如何,我知道我需要使用这个功能

- (CGPoint)targetContentOffsetForProposedContentOffset:withScrollingVelocity
Run Code Online (Sandbox Code Playgroud)

要做到这一点,但我只是使用标准UICollectionViewFlowLayout.我不是它的子类.

有没有任何方法可以在不进行子类化的情况下拦截这个UICollectionViewFlowLayout

谢谢

iphone ios uicollectionview

89
推荐指数
11
解决办法
6万
查看次数

如何从otf或ttf文件中获取字体名称?

我在之前的应用程序中使用了自定义字体.

文件名是"ProximaNova-Regular.otf"并加载我刚使用的字体...

[UIFont fontWithName:@"ProximaNova-Regular" size:20];
Run Code Online (Sandbox Code Playgroud)

这非常有效.

现在在这个新的应用程序中我有三个字体文件...

Dude_Willie.otf
Impact
handsean.ttf
Run Code Online (Sandbox Code Playgroud)

但我不知道如何加载这些.

我试过了

[UIFont fontWithName:<the file name> size:20];
Run Code Online (Sandbox Code Playgroud)

但这只是回到使用Helvetica.

如何找到要使用的名称?

uifont ios

76
推荐指数
8
解决办法
6万
查看次数

从 Xcode 分发时分析应用程序版本时出现什么错误?

我想分发应用程序,但收到错误消息。我不知道原因。

我使用 Xcode 版本 13.0 (13A233)

遇到错误:

 Error Analyzing App Version (Build number request failed with error: BuildsService: ResponseErrors (1): Error status: 403, code: FORBIDDEN_ERROR, title: 'This request is forbidden for security reasons', detail: 'The API key in use does not allow this request', id: 65cc1b85-e0d4-4f86-8bab-e72d7149c9cc)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

xcode ios

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

UITableView registerNib:forCellReuseIdentifier:

我在WWDC视频中看到过这个,但只是非常简短.他们没有介绍如何创建实际的xib文件.

我有一个名为MyCustomCell的UITableViewCell子类.在这里我有几个属性UILabels,UIImageViews等...都设置为IBOutlets.

现在,在我的xib文件中......

我将什么设置为文件的所有者?我在哪里引用我的MyCustomCell类是文件的所有者?

一旦我设置了文件的所有者,我如何将其与xib的根视图链接?

我尝试了一些设置,但在使用时我一直都会遇到错误.

哦,我用来注册它的代码是......

self.cellNib = [UINib nibWithNibName:@"MyCustomCell" bundle:nil];
[self.tableView registerNib:self.cellNib forCellReuseIdentifier:@"CustomCell"];
Run Code Online (Sandbox Code Playgroud)

谢谢

iphone uitableview

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

iOS正确使用@weakify(self)和@strongify(self)

我开始libextobjc(集成https://github.com/jspahrsummers/libextobjc)到我的iOS应用程序主要是为了充分利用EXTScope的中@strongify@weakify,但也继续深入过程之前,有几个问题.

这是一个有意过度复杂的例子,试图解决如何处理这个问题:

- (void)someMethod {
    if (self.someBOOL) {
        _someObjectInstanceVar = [Object objectWithCompletionHandler:^{
            // self reference #1
            if (self.someProperty) {
                // self reference #2
                [[Async HTTPRequest] sendAWithID:self.property.id completionHandler:^(void (^)(NewObject *newObject) {
                    // self reference #3
                    [self showViewWithObject:newObject handler:^{
                        // self reference #4
                        [self reloadData];
                    }];
                }];
            }
        }];

    else {
        [[Async HTTPRequest] sendBWithID:self.property.id completionHandler:^{
            // self reference #5
            [self reloadData];
        }];
    }
}
Run Code Online (Sandbox Code Playgroud)

我的理解是,如果我想做异步HTTP请求之类的事情,并且在完成处理程序引用self内部,比如[self reloadData],我不需要对强/弱做任何事情,因为请求块本身没有保留完成块,那里保留周期没有问题.在上面的代码示例中,我认为#5是保留周期不是问题的情况.

主要关注的是所有将块作为属性/ init参数的对象,这些对象内部保留在块属性上.在objectWithCompletionHandler方法内部,someObject作为实例变量保存在completionHandler块中,有多个对self的引用,我知道这会引起泄漏.我的主要问题是在这种情况下,您需要如何处理 …

objective-c ios libextobjc

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

〜= Swift中的运算符

我最近从Apple 下载了Advanced NSOperations示例应用程序,发现此代码...

// Operators to use in the switch statement.
private func ~=(lhs: (String, Int, String?), rhs: (String, Int, String?)) -> Bool {
    return lhs.0 ~= rhs.0 && lhs.1 ~= rhs.1 && lhs.2 == rhs.2
}

private func ~=(lhs: (String, OperationErrorCode, String), rhs: (String, Int, String?)) -> Bool {
    return lhs.0 ~= rhs.0 && lhs.1.rawValue ~= rhs.1 && lhs.2 == rhs.2
}
Run Code Online (Sandbox Code Playgroud)

它似乎使用~=运算符反对Strings,Ints但我以前从未见过它.

它是什么?

operators ios swift

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

iPhone AVFoundation摄像头方向

我一直在试图让我的头发试图让AVFoundation相机以正确的方向(即设备方向)拍摄图片,但我无法让它工作.

我看过教程,我看过WWDC演示文稿,我已经下载了WWDC示例程序,但即便如此也没有.

我的应用程序的代码是......

AVCaptureConnection *videoConnection = [CameraVC connectionWithMediaType:AVMediaTypeVideo fromConnections:[imageCaptureOutput connections]];
if ([videoConnection isVideoOrientationSupported])
{
    [videoConnection setVideoOrientation:[UIApplication sharedApplication].statusBarOrientation];
}

[imageCaptureOutput captureStillImageAsynchronouslyFromConnection:videoConnection
                                                completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error)
{
    if (imageDataSampleBuffer != NULL)
    {
        //NSLog(@"%d", screenOrientation);

        //CMSetAttachment(imageDataSampleBuffer, kCGImagePropertyOrientation, [NSString stringWithFormat:@"%d", screenOrientation], 0);

        NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
        UIImage *image = [[UIImage alloc] initWithData:imageData];

        [self processImage:image];
    }
}];
Run Code Online (Sandbox Code Playgroud)

(processImage使用与WWDC代码相同的writeImage ...方法)

并且WWDC应用程序的代码是......

AVCaptureConnection *videoConnection = [AVCamDemoCaptureManager connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
        if ([videoConnection isVideoOrientationSupported]) {
            [videoConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
        }

[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
                                                             completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
                                                                 if …
Run Code Online (Sandbox Code Playgroud)

iphone camera avfoundation orientation

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

更改iPhone UISlider条形图

UISlider在我的应用程序中使用了一个,但我想使用自定义的"外观和感觉".我已经将拇指改为我自己的形象,但有没有办法改变吧?我有一个我想使用的条形图,但看不到如何做到这一点.

我已经找到了如何更改最大和最小图像而不是条形本身.

iphone image objective-c uislider ios

31
推荐指数
4
解决办法
5万
查看次数

UIQueuingScrollView中的断言失败didScrollWithAnimation:force:

我有一个UIPageViewController设置寻呼我的ImageViewController.

ImageViewController包含UIScrollView有一个UIImageView内部.没有其他的.

我正在测试我的数据源中的3个"项目" UIPageViewController(即三页).

这一切都很好,我可以滚动和缩放,然后页面约30秒,然后我突然得到这个警告......

*** Assertion failure in -[_UIQueuingScrollView _didScrollWithAnimation:force:], /SourceCache/UIKit/UIKit-2372/_UIQueuingScrollView.m:778
Run Code Online (Sandbox Code Playgroud)

我不知道从哪里开始调试它,因为它没有指向我的任何代码,并且堆栈中没有任何代码或任何东西.

有人可以给我一个指针,指出从哪里开始调试这个.

编辑

我做了一些测试.如果scrollView正在减速(即在轻弹之后)似乎会发生,然后我尝试将PageViewController转换到另一个ViewController,因为scrollview仍在移动.

该应用程序在转换到下一页的过程中崩溃了大约20%.

编辑2

错误似乎停在了_cache_getImp行(不确定这是大写字母i还是小写字母L).

编辑3

这变得更好.我刚刚下载了Apple的PhotoScroller示例应用程序,看看他们是否以不同的方式解决了问题.嗯,不,他们没有.示例应用程序以与我的方式完全相同的方式崩溃!你必须同时缩放,滚动和转换页面,以使其更容易崩溃,但它也可能发生在它自己也可能需要更长时间才能发生.

iphone ios uipageviewcontroller

31
推荐指数
2
解决办法
6849
查看次数

Xcode配置文本字段失去焦点

我最近升级到Xcode 6.2.好像有一个奇怪的错误.例如,如果我想更改包ID,则在输入任何字符后,文本字段将失去焦点.

有人有同样的问题吗?有谁知道如何解决这个问题?

这对我来说非常烦人,我猜其他任何人也是如此.

xcode ios xcode-6.2

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