Tag: 迅速

应用程序内购买电话function成功时

我有一个button,它应该隐藏屏蔽用户从使用扩展到应用程序的背景视图的产品。 当按下button时,购买产品的代码来自外部文件。 正因为如此,购买成功后,我才知道隐藏视图的方法。 来自其他文件的代码 for transaction: AnyObject in transactions { if let trans: SKPaymentTransaction = transaction as? SKPaymentTransaction { switch trans.transactionState { case .purchased: print("Product Purchased") let purchased = UserDefaults.standard.bool(forKey: "Analytics") UserDefaults.standard.set(true, forKey: "Analytics") 是否有可能从一个外部的swift文件调用一个视图控制器类的function? 你还有什么办法可以解决这个问题?

在sceneKit View,iOS,Swift中获取像素颜色

我尝试在sceneKit视图中获取特定像素的颜色。 不过,我只能看到我背景的颜色。 在我的场景中,我有一个带有纹理图像的球体。 有人可以帮我吗? import UIKit extension UIView { func getColourFromPoint(point:CGPoint) -> UIColor { let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()! let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue) var pixelData:[UInt8] = [0, 0, 0, 0] let context = CGBitmapContextCreate(&pixelData, 1, 1, 8, 4, colorSpace, bitmapInfo.rawValue) CGContextTranslateCTM(context, -point.x, -point.y); self.layer.renderInContext(context!) let red:CGFloat = CGFloat(pixelData[0])/CGFloat(255.0) let green:CGFloat = CGFloat(pixelData[1])/CGFloat(255.0) let blue:CGFloat = […]

更改Coreplotgraphics的勾号标签

我在我的Mac应用程序中使用coreplot来处理graphics,并且工作正常。 我有一个要求,显示custom labels沿轴的滴答如: 我有一个功率值随时间变化的图表: Power values -> Y-Axis和Time -> X-Axis 。 I want to draw graph for Time seconds values but show fixed intervals ticks of minutes along x-axis for which i figured that i should use custom labels but its not happening for me. 自定义标签的代码是: let graph = CPTXYGraph() plots[0].identifier = PlotType.target.rawValue plots[1].identifier = […]

Swift 2.1核心数据 – 保存具有一对多关系的数据,但如果已经存在,则不要添加等值数据

我有一个ViewController创build一个新的配方数据。 要创build一个新的配方,用户需要填写标题,配料等,并select其类别。 为此,我build立了一对多关系的类别和食谱实体。 在创build函数中,我将需要进行以下search以查看类别实体是否已具有selectedCategory的值。 如果selectedCategory已经存在于Category实体中,我需要find它的索引并将该类别分配给Recipe实体,但是我不知道在这里需要写什么代码。 for category in categories { if category == selectedCategory { /* if selectedCategory already exists in Category entity, find its index and assign that category to Recipe entity.*/ } else { category.name = selectedCategory recipe.category = category } } context.insertObject(recipe) do { try context.save() } catch { print("Could not save […]

容器视图inheritance到相同大小的视图控制器

我有以下的故事板: 到目前为止,如果我通过显示继续播放,我只能在故事板中实现相同大小的第三个视图控制器,但我更喜欢自定义方法。 我的目标是从第二个视图控制器继续到第三个视图控制器,并且只replace在(第一个)视图控制器中是一个容器视图的第二个视图控制器。 但是目前的产出: 预期产出: 我怎样才能做到这一点? 谢谢,

使用Apple TV上的多个控件pipe理焦点

我的屏幕上有多个控件。 在右上方的集合视图,然后是左中心的button,除了button,我有另一个集合视图。 请参阅附件图片 我能够将焦点从button移动到底部收集视图,反之亦然。 我已经为以下内容创build了一个重点指南: focusGuide.preferredFocusedView = self.btn self.view.addLayoutGuide(self.focusGuide) self.focusGuide.topAnchor.constraintEqualToAnchor(collectionViewHeader.topAnchor).active = true self.focusGuide.bottomAnchor.constraintEqualToAnchor(collectionViewBottom.topAnchor).active = true self.focusGuide.leadingAnchor.constraintEqualToAnchor(collectionViewBottom.leadingAnchor).active = true self.focusGuide.widthAnchor.constraintEqualToAnchor(collectionViewBottom.widthAnchor).active = true 并在didUpdateFocusInContext:,我写: override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) { super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator) guard let nextFocusedView = context.nextFocusedView else { return } if(nextFocusedView .isKindOfClass(bottomCell)) { self.focusGuide.preferredFocusedView = self.btn } else { self.focusGuide.preferredFocusedView = self.collectionViewBottom } […]

如何将ios-chart约束为视图的大小

编辑简短的版本:我正在显示一个graphics使用dynamic数据的ios图表,它正在切断我的图表,因此图表的完整垂直部分显示不正确。 某些操作(如从风景转换为人像或反之亦然)会导致graphics正确显示。 原来的问题 我正在iPhone 6模拟器上运行ios 9.3,使用ios-charts版本2.2.4显示线图,而且我遇到了内容被垂直剪切的问题… 有时 。 该图表是一个下钻图表,通过在另一个图表中select一个数据点来触发。 对于某些数据点,如果我先select它们,那么钻取图表会被剪切,如下所示: 但是,如果我先select另一个数据点,然后重新select刚刚裁剪的相同数据点 ,则图表或多或less会按预期呈现: 我手动设置图表的最大Y值,并打印最大的Y值确认它确实被设置,所以我留下来相信,问题不在于图表格式,但可能以图表约束的方式本身的观点? 换句话说,也许这是一个布局/故事板的问题,有一个属性,我可以设置视图,甚至父视图,使这个渲染正确? 但是,这里是我用来生成图表的代码,以防万一我做了任何明显错误的事情: … // Part where I actually get the data omitted bc its boring let chartDataSet = LineChartDataSet(yVals: dataEntries, label: "") let chartData = LineChartData(xVals: xVals, dataSet: chartDataSet) drilldownChart.data = chartData formatChart(drilldownChart, yMax: [runningTotal, Double(goal.target)].maxElement()!) chartDataSet.colors = [UIColor.blackColor()] chartDataSet.circleColors = [UIColor.blackColor()] […]

无法将types'CFString'的值转换为期望的参数types'UnsafePointer <Void>'(又名'UnsafePointer <()>')

当我定义行时,出现构build错误 let runFont : CTFontRef = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName) 错误是:无法将types'CFString'的值转换为期望的参数types'UnsafePointer'(又名'UnsafePointer <()>')

在Swift3 iOS10中replaceCFURLCreateStringByAddingPercentEscapes?

我知道在CFURLCreateStringByAddingPercentEscapes中不build议使用stringByAddingPercentEncodingWithAllowedCharacters方法,它build议我使用stringByAddingPercentEncodingWithAllowedCharacters ,但是我没有使用UTF-8,我怎样才能使用stringByAddingPercentEncodingWithAllowedCharacters来做同样的事情,如下所示: extension String { var gbkEncoded: String { let cfEnc = CFStringEncodings.GB_18030_2000 return CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, self as CFString!, nil, nil, CFStringEncoding(cfEnc.rawValue)) as String } }

领域对象缺less除primaryKey之外的所有属性

我有我的tableViewDataSource依赖的RealmObject模型。 cellForRowAtIndexPath1方法能够很好地访问属性,但didSelectRowAtIndexPath从Realm对象中获取所有空属性。 我猜这与传递持续的Realm对象有关,但我不知道在哪里解决它。 //viewController… override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) let realm = try! Realm() let books = realm.objects(Book) viewModel = BookListViewModel(books: Array(books), onSelection: onSelection, onDeleteFailure: onDeleteFailure) } //end viewController extension BookListViewModel: UITableViewDataSource { func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier(BookTableViewCell.nibName, forIndexPath: indexPath) as! BookTableViewCell cell.bind(bookCellViewModels[indexPath.row]) // NOTE: // […]