小编sas*_*ash的帖子

从后台任务启动iOS 7中的位置管理器

似乎在iOS 7中,应用程序无法再从后台任务启动位置管理器(通过调用startUpdatingLocation).

在iOS 6中,我使用了这里描述的方法:https://stackoverflow.com/a/6465280每n分钟运行一次后台位置更新.我们的想法是使用计时器运行后台任务,并在计时器触发时启动位置管理器.之后关闭位置管理器并启动另一个后台任务.

更新到iOS 7后,此方法不再起作用.启动位置管理器后,应用程序不会收到任何locationManager:didUpdateLocations.有任何想法吗?

objective-c core-location cllocationmanager ios ios7

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

heightForRowAtIndexPath中的当前单元格高度?

我有一张带静电池的桌子.对于一个单元格,我想根据标签的高度(在单元格内部)更改其高度,同时保持所有其他单元格的高度不变.我怎样才能获得当前细胞的高度?或者也许有更好的方法?

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([indexPath section] == 2) {
        return self.myLabel.frame.origin.y *2 + self.myLabel.frame.size.height;
    } else {
        return ...; // what should go here, so the cell doesn't change its height?
    }
}
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

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

带圆角的虚线

我试图在这样的视图周围绘制带圆角的虚线:

class DashedLineView: UIView {

    override func draw(_ rect: CGRect) {

        let path = UIBezierPath(roundedRect: rect, cornerRadius: 8)

        UIColor.clear.setFill()
        path.fill()

        UIColor.red.setStroke()
        path.lineWidth = 3

        let dashPattern : [CGFloat] = [3, 3]
        path.setLineDash(dashPattern, count: 2, phase: 0)
        path.stroke()
    }
}
Run Code Online (Sandbox Code Playgroud)

结果是:

在此输入图像描述

你可以看到角落有问题,任何想法如何修复它?

更新: 使用@Jon Rose 答案 DashedLineView现在看起来像这样:

class DashedLineView: UIView {

    private let borderLayer = CAShapeLayer()

    override func awakeFromNib() {

        super.awakeFromNib()

        borderLayer.strokeColor = UIColor.red.cgColor
        borderLayer.lineDashPattern = [3,3]
        borderLayer.backgroundColor = UIColor.clear.cgColor
        borderLayer.fillColor = UIColor.clear.cgColor

        layer.addSublayer(borderLayer)
    }

    override func draw(_ rect: CGRect) …
Run Code Online (Sandbox Code Playgroud)

core-graphics uibezierpath swift

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

没有圆角的UIPopoverBackgroundView

我通过继承UIPopoverBackgroundView来制作自定义popover背景.我想制作没有圆角的弹出窗口.我可以成功创建没有圆角的背景(图片中的红色),但似乎UIPopoverController在弹出框的内容中添加了一些圆角掩模(绿色图片).这是我的popover角落的图片:

在此输入图像描述

我有什么想法可以克服它吗?

objective-c uipopovercontroller ios uipopoverbackgroundview

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

使用多行标签时systemLayoutSizeFittingSize返回错误的大小

我有一个自定义表格单元格MyCell,只有1个多边形标签,边框有约束.xib大小是 320 x 280. 在此输入图像描述

systemLayoutSizeFittingSize用来根据内容计算单元格高度:

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];

        // set cell width = table width
        CGRect rect = cell.frame;
        rect.size.width = CGRectGetWidth(tableView.frame);
        cell .frame= rect;

        // update the text
        cell.mainLabel.text = @"Some multiline text. Some multiline text. Some multiline text. Some multiline text. Some multiline text. Some multiline text. Some multiline text. Some multiline text.";

        [cell setNeedsLayout];
        [cell layoutIfNeeded];

        CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];

        NSLog(@"size %@", …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview uilabel autolayout

7
推荐指数
3
解决办法
5667
查看次数

SwiftUI 工作表在第一次出现时就被忽略了

这个错误快把我逼疯了。有时(大多数情况下)呈现的工作表在第一次打开时会被忽略。这种情况仅发生在设备上并且仅在应用程序第一次启动时发生。这是使用 Xcode 12.1 构建的运行 iOS 14.1 的 iPhone 11 上的外观(也可以在运行 iOS 14.0.1 的 iPhone 7 Plus 上重现):

在此输入图像描述

视频中的步骤:

  1. 我打开应用程序
  2. 快速导航到详细信息视图
  3. 打开表
  4. 红衣被系统解雇???
  5. 我再次打开工作表,它仍按预期保留在屏幕上。

这是SwitUI App项目(使用UIKIt App Delegate)和部署iOS 14。代码:

struct ContentView: View {
   
    var body: some View { 
        NavigationView {
            NavigationLink(destination: DetailsView()) {
                Text("Open Details View")
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
    }
}

struct DetailsView: View {
   
    @State var sheetIsPresented: Bool = false
 
    var body: some View {
        VStack {
            Button("Open") {
                sheetIsPresented.toggle()
            }
        }.sheet(isPresented: $sheetIsPresented, content: {
            SheetView()
        })
    } …
Run Code Online (Sandbox Code Playgroud)

swift swiftui

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

可以测试IBAction吗?

对IBOutlets进行单元测试有点容易,但IBActions呢?我试图找到一种方法,但没有任何运气.有没有办法在View Controller中的IBAction和nib文件中的按钮之间进行单元测试连接?

ocunit ios xctest

6
推荐指数
3
解决办法
6566
查看次数

使用 Firebase/Analytics pod 时 SwiftUI 预览不起作用

似乎在将 Xcode 12 更新到 beta 5 后,SwiftUI 预览在使用 Firebase/Analytics pod 时不再起作用。预览失败并出现错误:

linker command failed with exit code 1 (use -v to see invocation)

----------------------------------------

SchemeBuildError: Failed to build the scheme "Boo"

linker command failed with exit code 1 (use -v to see invocation)


Link Boo (arm64):
ld: in /Users/../Boo/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector(FIRAnalyticsConnector_e321ed8e3db06efc9803f6c008e67a34.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/.../Boo/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation) …
Run Code Online (Sandbox Code Playgroud)

ios firebase-analytics swiftui xcode12

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

MKMapView设置缩放限制而不弹跳

关于MKMapView的最大缩放的stackoverflow有很多问题和答案,例如:

有没有办法限制MKMapView的最大缩放级别?

不幸的是,没有答案实际上对我有用(或者我没有正确实施).我无法模拟原生地图的行为,即限制缩放级别而不"反弹"或重新恢复.

这是我使用的代码:

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{ 
    if( mapView.region.span.latitudeDelta<0.001 || mapView.region.span.longitudeDelta<0.001){
        MKCoordinateRegion region =mapView.region;
        region.span = MKCoordinateSpanMake(0.001, 0.001);
        mapView.region = region;
        [mapView setRegion:mapView.region animated:NO];
    }
}
Run Code Online (Sandbox Code Playgroud)

当用户捏合和缩放地图并且地图达到最大缩放(由我设置)时,地图不应放大然后反弹.可能吗?

objective-c mapkit mkmapview ios mkmapviewdelegate

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

如何将灰色背景添加到自定义UIPopoverBackgroundView

我通过继承UIPopoverBackgroundView(使用本教程)并使用UIPopoverController呈现它来制作自定义弹出窗口.不幸的是,只要我指定自定义popoverBackgroundViewClass,原生的灰色背景就会消失.使用自定义UIPopoverBackgroundView时,有没有办法让灰色背景变暗?我可以用来模拟本机行为的任何其他解决方案?

objective-c uipopovercontroller uipopoverbackgroundview

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