小编Luk*_*ger的帖子

NSCollectionViewItem双击动作?

当用户双击时,如何设置操作NSCollectionViewItemNSTableView,例如,具有setDoubleAction方法。有类似的东西NSCollectionView吗?

谢谢

cocoa objective-c nscollectionview nscollectionviewitem

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

为djinni定义const getters

我用djinni定义了一个C++接口:

member = interface +c {
    get_id(): string;
    get_name(): string;
}
Run Code Online (Sandbox Code Playgroud)

我继承的实现使用const getters,即

class MyMemeber: public Member {
  private:
    string id;
    string name;
  public:
    string get_id() const override { return id; }
    string get_name() const override { return name; }
}
Run Code Online (Sandbox Code Playgroud)

由于const属性,这显然无法编译.我可以教djinni用const getters生成基本接口吗?

c++ java-native-interface const djinni

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

如何使用 URLSession 从 url 获取 JSON 数据?

我正在开发一个 iOS 应用程序,我必须从这个 url获取数据。

我可以看到这个 url 包含 JSON 数据,所以这里我是否需要解析它,我不知道如何获取这个 JSON 数据。

这是我的代码。

import UIKit
import SwiftyJSON

typealias ServiceResponse = (ApiResponseData, NSError?) -> Void

class ApiManager: NSObject {

    var session:URLSession? = nil
    var urlRequest:URLRequest? = nil

    override init(){
        super.init()

        urlRequest = URLRequest(url: URL(string:"https://dl.dropboxusercontent.com/s/2iodh4vg0eortkl/facts.json")!)
        urlRequest?.addValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
        session = URLSession(configuration: .default)

    }

    func callRestApiToFetchDetails(onCompletion: @escaping ServiceResponse) {
        let task = session?.dataTask(with: urlRequest!, completionHandler: {data, response, error -> Void in
            print("Response = \(data)")

            do {
                let jsonData = try JSONSerialization.jsonObject(with: …
Run Code Online (Sandbox Code Playgroud)

json ios nsurlsession swift

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

如何基于Angular4中的条件禁用跨度

我正在Angular4应用程序中工作,我想根据条件处理跨度(启用/禁用)。

当购物车中没有物品时,我要禁用跨度。

但是,当购物车中至少有1件商品时。跨度将被启用。

在此处输入图片说明

 <span class=" notification-counter badge badge-danger" data-toggle="modal" data-target="#exampleModal" style="cursor: pointer;">{{nCount}}</span>
Run Code Online (Sandbox Code Playgroud)

从HTML或打字稿方面,我该如何处理。

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DatePipe } from '@angular/common';
import { HostListener } from '@angular/core';
import {CartdataService} from './cartdata.service';


@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']

})

export class AppComponent implements OnInit{
    nCount : string;
    constructor(private CartdataService:CartdataService,private http: HttpClient) { }

    ngOnInit() {
        this.CartdataService.cast.subscribe(Count=> this.nCount = Count);

    }
}
Run Code Online (Sandbox Code Playgroud)

html angular

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

iOS中的静态/固定导航栏

我的应用程序内部有一个导航控制器和一个集合视图。有一个问题:我在导航栏中使用大标题,因此里面的所有内容都不是静态的。当我滚动集合视图单元格时,标题(我手动创建了该标题,并使用UILabel()它在导航栏中随意移动它)和按钮向上移动,导航栏采用iOS 10导航栏的形式,即其高度。你可以在这里看到它:

我的导航栏带有“首选大标题”的正常状态开:

当我滚动“收藏夹视图”时,一切都会发生:

所以问题很简单:如何使导航条的力保持恒定的高度?我希望它即使在滚动时也能固定。有什么想法吗?可能吗?

第二个问题,如果第一个是不可能的:我的问题的另一种解决方案是使“优先选择大标题”的导航栏更大。我尝试了这段代码:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    let height: CGFloat = 50 //whatever height you want to add to the existing height
    let bounds = self.navigationController!.navigationBar.bounds
    self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
}
Run Code Online (Sandbox Code Playgroud)

但它仅适用于大标题。那么如何使导航栏更大?

uinavigationcontroller ios swift

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

创建一个包含 2 个 UiView 的水平 Stackview

我想要的是:

我想以Views水平方式并排放置 2 个。为此,我正在以UIStackView编程方式创建。看下面的片段

我做了什么:

let mStackView = UIStackView()
mStackView.axis  = UILayoutConstraintAxis.horizontal
mStackView.distribution  = UIStackViewDistribution.fillEqually
mStackView.alignment = UIStackViewAlignment.center
mStackView.spacing = 10
Run Code Online (Sandbox Code Playgroud)

现在在这个里面我想放 2 UIView。每个UIView将保持中心对齐UIImageUILabel。为此,我UIStackView在每个中使用另一个UIView

看看这个片段。

let mDonationView = UIView()
mDonationView.backgroundColor = UIColor.green

let SV = UIStackView()
SV.axis  = UILayoutConstraintAxis.vertical
SV.distribution  = UIStackViewDistribution.fill
SV.alignment = UIStackViewAlignment.leading
SV.spacing = 1
SV.alignment = .top

let imageName = "Donate"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
imageView.frame …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift uistackview

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

在Swift中动画自定义UIView属性

所有!

我使用CoreGraphics外观和更新创建了一个循环进度视图,如下所示:

50% 在此输入图像描述 75% 在此输入图像描述

该类是一个UIView类,它有一个名为"progress"的变量,用于确定填充了多少圆.

它运行良好,但我希望能够对progress变量进行动画处理,以使条形图平滑动画.

我从无数的例子中读到,我需要有一个CALayer类和View类,我已经制作了它,但它根本没有动画.

两个问题:

  1. 我可以保留我绘制的图形CoreGraphics,还是需要以某种方式重绘它CALayer
  2. 我当前(尝试过的)解决方案在底部崩溃:anim.fromValue = pres.progress.这是怎么回事?

    class CircleProgressView: UIView {
        @IBInspectable var backFillColor: UIColor = UIColor.blueColor()
        @IBInspectable var fillColor: UIColor = UIColor.greenColor()
        @IBInspectable var strokeColor: UIColor = UIColor.greenColor()
    
        dynamic var progress: CGFloat = 0.00 {
            didSet {
                self.layer.setValue(progress, forKey: "progress")
            }
        }
    
        var distToDestination: CGFloat = 10.0
        @IBInspectable var arcWidth: CGFloat = 20
        @IBInspectable var outlineWidth: CGFloat = 5
    
        override class func …
    Run Code Online (Sandbox Code Playgroud)

animation calayer uiview ios

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

.usdz 模型加载到场景时没有纹理

我正在将 .usdz 模型(从 Apple 下载)加载到我的ARSCNSceneView工作中。但不幸的是,该模型始终渲染为没有任何纹理并且显示为黑色。

// Get the url to the .usdz file
guard let usdzURL = Bundle.main.url(forResource:   "toy_robot_vintage", withExtension: "usdz")
else {
    return
}

// Load the SCNNode from file             
let referenceNode = SCNReferenceNode(url: usdzURL)!
referenceNode.load()

// Add node to scene
sceneView.scene.rootNode.addChildNode(referenceNode)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

augmented-reality scenekit swift arkit usdz

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

TypeError:Object(...)不是角度材料的函数

在角度7中,尝试使用角度材料mat-dialog-content。导入app.module.ts时会出现以下错误:

TypeError:Object(...)不是类似的函数:未捕获TypeError:Object(...)不是platform.es5.js:102上的函数。

package.json

{
  "name": "image-cropp",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.15",
    "@angular/cdk": "^8.0.1",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/material": "^8.0.1",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "core-js": "^2.5.4",
    "ngx-image-cropper": "^1.4.1",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.5",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": …
Run Code Online (Sandbox Code Playgroud)

angular-material angular angular7

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

如何在swiftUI中创建普通视图

我正在尝试在SwiftUI中使用背景色创建纯视图。但是我能找到的所有内容都不是纯文本格式的元素,例如文本,按钮,图像,列表等。

当我尝试使用时View,它显示以下错误消息:

  • 无法构建“视图”,因为它没有可访问的初始化程序
  • “查看”协议只能用作一般约束,因为它具有Self或associatedType要求

如何创建具有背景色的矩形视图?

view ios swift ios13 swiftui

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