小编ZGs*_*ski的帖子

在Swift中将Float转换为Int

我想将转换FloatInt斯威夫特.像这样的基本转换不起作用,因为这些类型不是基元,与Objective-C中的floats和ints 不同

var float: Float = 2.2
var integer: Int = float as Float
Run Code Online (Sandbox Code Playgroud)

但是这会产生以下错误消息:

'Float'不能转换为'Int'

知道如何将属性转换FloatInt

casting type-conversion swift

190
推荐指数
6
解决办法
19万
查看次数

distanceFromLocation - 计算两点之间的距离

关于Core Location的一个简单问题,我正在尝试计算两点之间的距离,代码如下:

    -(void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation
    {   

    // Configure the new event with information from the location.
        CLLocationCoordinate2D newCoordinate = [newLocation coordinate];
        CLLocationCoordinate2D oldCoordinate = [oldLocation coordinate];

        CLLocationDistance kilometers = [newCoordinate distanceFromLocation:oldCoordinate] / 1000; // Error ocurring here.
        CLLocationDistance meters = [newCoordinate distanceFromLocation:oldCoordinate]; // Error ocurring here.
}
Run Code Online (Sandbox Code Playgroud)

我在最后两行收到以下错误:

错误:无法转换为指针类型

我一直在搜索谷歌,但我找不到任何东西.

objective-c core-location ios

49
推荐指数
4
解决办法
8万
查看次数

如何在Swift中弹出特定的View Controller

我使用Objective-C下面的代码来弹出特定的代码ViewController.

for (UIViewController *controller in self.navigationController.viewControllers) {
    if ([controller isKindOfClass:[AnOldViewController class]]) { 
        //Do not forget to import AnOldViewController.h
        [self.navigationController popToViewController:controller
                                              animated:YES];
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎么能在Swift中做到这一点?

uiviewcontroller ios swift

28
推荐指数
8
解决办法
5万
查看次数

无声推送通知有效负载

我只是想问一下如何确定在静音推送上要采取的行动:

这是我发给客户的aps:

"aps": {
    "content-available": 1
}
Run Code Online (Sandbox Code Playgroud)

我现在的问题是当我添加类型:"Order_Update"以确定静默推送是针对订单更新它显示警报通知

push-notification apple-push-notifications ios swift

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

如何在 SwiftUI 中使用 SegmentedPickerStyle() 更改选择器的高度?

如何在 SwiftUI 中更改选择器框架?

Picker(selection: .constant(1), label: Text("Picker")) {
    Text("Hello").tag(1)
    Text("World").tag(2)
}
.frame(height: 60)
.pickerStyle(SegmentedPickerStyle())
Run Code Online (Sandbox Code Playgroud)

我们希望选择器高度等于60,但事实并非如此。

ios swift swiftui

11
推荐指数
2
解决办法
1878
查看次数

如何将Int转换为String.CharacterView.Index

这让我疯了.

在雨燕2.2,这使得它不可能下标StringInt.例如:

let myString = "Test string"
let index = 0
let firstCharacter = myString[index]
Run Code Online (Sandbox Code Playgroud)

这将导致编译错误,说

'subscript'不可用:不能使用Int下标String,请参阅文档注释以供讨论

我看到的一个解决方法是将整数转换为索引类型,但我无法弄清楚如何...

string subscript swift2 swift2.2

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

以编程方式设置约束优先级

我需要以.xib编程方式重新创建基于布局的布局。

我在很大程度上能够实现这一点,但是,无法设置我的一位主播的优先级。

我试图在代码中重现的设置是:

xib 约束

我以为我可以设置它,setContentHuggingPriority(.init(999), for: .vertical)但这没有效果。

如何在代码中定位此属性?

autolayout nslayoutconstraint swift

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

Swift:Bolding UIButton


是否可以在UIButton中加粗字体?有了标签,它非常简单,例如:

label.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)
Run Code Online (Sandbox Code Playgroud)

但这不适用于按钮.

label uibutton uifont swift

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

可选类型“UIImage?”的值 没有打开

我正在尝试创建一个简单的过滤器应用程序,在按下按钮时过滤显示的图像。

 @IBAction func applyFilter(sender: AnyObject) {

    // Create an image to filter
    let inputImage = CIImage(image: photoImageView.image)

    // Create a random color to pass to a filter
    let randomColor = [kCIInputAngleKey: (Double(arc4random_uniform(314)) / 100)]

    // Apply a filter to the image
    let filteredImage = inputImage.imageByApplyingFilter("CIHueAdjust", withInputParameters: randomColor)

    // Render the filtered image
    let renderedImage = context.createCGImage(filteredImage, fromRect: filteredImage.extent())

    // Reflect the change back in the interface
    photoImageView.image = UIImage(CGImage: renderedImage)

}
Run Code Online (Sandbox Code Playgroud)

我不断收到错误:

可选类型“UIImage?”的值 没有解开。

我在这里做错了什么?我是 Swift 初学者。

optional uiimage ios swift

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

即使指定 contentShape 后,ContextMenu 仍使用不正确的cornerRadius

struct CardView: View {
    private var name: String = "Random Name"
    private var color: Color = Color.red
    
    private var CardContent: some View {
        HStack(alignment: .top) {
            Text(name)
                .font(.system(size: 16, weight: .medium, design: .rounded))
                .frame(width: 110, height: 80, alignment: .top)
        }
        .padding(.top, 20)
        .frame(width: 200, height: 190, alignment: .top)
        .background(color)
        .clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
    }
    
    var body: some View {
        CardContent
            .contentShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
            .contextMenu {
                Button(action:{}){
                    HStack {
                        Image(systemName: "trash")
                            .foregroundColor(Color.red)
                        Text("Delete")
                    }
                }
        }
        .shadow(color: color.opacity(0.5), radius: 10, …
Run Code Online (Sandbox Code Playgroud)

contextmenu ios swift swiftui

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

如何使用iOS PDFKit以编程方式填写PDF表单字段

在此处输入图片说明 在我的应用程序中,我有一个基于用户输入的PDF表单。我在PDF表单中强制输入该值。我ILPDFKit在我的应用程序中使用了pod来执行此操作(swift 3,但是由于PDFKit在iOS 11中已经存在,所以我想知道使用PDFKit是否可以实现)。我使用的代码ILPDFKit是:

// set the pdf form as ILPDFDocument  
let document = ILPDFDocument(resource:"ExamplePDFfrom")

// Manually set a form value for field name (created in adobe acrobat)
document.forms.setValue("David", forFormWithName: "FirstName") 
Run Code Online (Sandbox Code Playgroud)

annotations pdfkit ios swift

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

将其他视图添加到UIButton

我想为a添加一些视图UIButton.例如,多个UILabels,UIImages等等.我添加了这些视图,但它们没有获得触摸事件.我怎样才能将触摸事件传递给UIButton

谢谢

uibutton uiview ios

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

Javascript范围变量

输出为15(在f中,x为10,y为7),具有以下内容:

var x = 5;
function f(y) { return (x + y) - 2};
function g(h) { var x = 7; return h(x) };
{ var x = 10; z = g(f); console.log(z) };
Run Code Online (Sandbox Code Playgroud)

为什么x取第4行而不是第1行的值(为什么不是第3行)?

javascript scoping

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