我有一个UICollectionView与segmented control数据之间切换.但是如何以编程方式更改UICollectionViewCell大小属性?然后我可以为每种数据类型适当地定制每种样式.
例如,将宽度更改为520点,将高度更改为100.我是iOS开发新手,对CSS有经验:/
我知道如何在Xcode中做(显然),但不知道在swift中更改它的正确方法.非常感谢任何想法或反馈(Y)
我有一个Gradient类,我试图转换为Swift 3但我得到以下错误
'CGPointMake'在swift中不可用
对于
func configureGradientView() {
let color1 = topColor ?? self.tintColor as UIColor
let color2 = bottomColor ?? UIColor.black as UIColor
let colors: Array <AnyObject> = [ color1.cgColor, color2.cgColor ]
let layer = self.layer as! CAGradientLayer
layer.colors = colors
layer.startPoint = CGPointMake(startX, startY)
layer.endPoint = CGPointMake(endX, endY)
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我解决我可以使用的问题而不是 CGPointMake
这是全班;
@IBDesignable public class XGradientView: UIView {
@IBInspectable public var topColor: UIColor? {
didSet {
configureGradientView()
}
}
@IBInspectable public var bottomColor: UIColor? {
didSet {
configureGradientView()
} …Run Code Online (Sandbox Code Playgroud) 我试图使用当地货币显示应用内购买的价格,因此显示美国和加拿大以及欧元,英镑等的正确美元.
我知道每个SKProduct都有一个在交易过程中出现的价格作为警报视图,这在确认购买时出现.
但是我想在确认之前显示价格.
我当时想做这样的事情:
//Products Array
var productsArray: Array<SKProduct!> = []
//Request Products
func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
if response.products.count != 0 {
for product in response.products {
print("\(product.localizedTitle)")
productsArray.append(product)
}
}
else {
print("There are no products.")
}
if response.invalidProductIdentifiers.count != 0 {
print("\(response.invalidProductIdentifiers.description)")
}
}
let item = SKProduct
for i in productsArray {
if i.localizedTitle == "com.Company.App.item1"
item = i
}
}
Run Code Online (Sandbox Code Playgroud)
但这i不起作用似乎没有价格属性.
有人知道如何使用正确的本地货币将标签文本设置为iAP的价格吗?
例如,使用苹果定价矩阵1.49英镑是1.99美元,并且在确认交易时输出的值应该与产品价格的值相匹配.
我想要实现的是当用户创建,更改或删除数据时,persistent store它将与之同步,iCloud store然后更新登录到同一iCloud帐户的其他设备.
我创建了一个Core Data Stack使用Objective-C资源并尝试在Swift中编写自己的资源,但是我在使用登录到同一个iCloud帐户的两个设备同步数据时遇到问题.
例如,当iDevice A登录到iCloud时,它会将数据备份到iCloud,但是当iDevice B登录到iCloud时,应用程序会删除持久存储上已有的任何数据以保存iCloud备份,并且不会出现商店设备之间的任何更改在另一方面,但似乎保存到iCloud商店作为最新的备份,所以如果应用程序被删除并重新安装我看到其他设备做的最新备份 - 考虑到这一点,如果iDevice B已经登录,它除非重新安装应用程序并且最后一次备份是由其他设备完成的,否则不会使用来自iDevice A的数据.
有人知道在Core data stack使用相同的iCloud帐户在两台设备之间同步数据时我出错了吗?
核心数据堆栈:
// MARK: - Core Data stack
// All the following code is in my appDelgate Core data stack
func observeCloudActions(persistentStoreCoordinator psc: NSPersistentStoreCoordinator?) {
// Register iCloud notifications observers for;
//Stores Will change
//Stores Did Change
//persistentStoreDidImportUbiquitousContentChanges
//mergeChanges
}
//Functions for notifications
func mergeChanges(notification: NSNotification) {
NSLog("mergeChanges notif:\(notification)") …Run Code Online (Sandbox Code Playgroud) 我有一个Core Spotlight用于索引应用内容的应用.该应用程序还使用Core Data,并在创建NSManagedObject对象的详细信息时使用,CSSearchableItem然后添加到Spotlight Search Index.
事情是,我的印象是,没有方向参考下NSManagedObject和CSSearchableItem,所以当项目被添加到索引,它只是复制的细节.
以下是将项添加到索引的示例.
//Spotlight Index Search
// Create an attribute set to describe an item.
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeData as String)
// Add metadata that supplies details about the item.
attributeSet.title = "\(object.title)"
attributeSet.contentDescription = "\(object.description)"
// Create an item with a unique identifier, a domain identifier, and the attribute set you created earlier.
let item = CSSearchableItem(uniqueIdentifier: "1", domainIdentifier: "ObjectType", …Run Code Online (Sandbox Code Playgroud) 我正在尝试检测设备何时在 iPad 上且处于纵向状态。
目前我使用UIDeviceUIKit 中的 API 并使用环境对象来观察变化。我使用此处找到的解决方案 -确定当前设备和方向.
然而orientationInfo.orientation最初总是等于.portrait until rotated into portrait and then back to landscape.
因此,当执行以下操作来显示FABView
struct HomeView: View {
@EnvironmentObject var orientationInfo: OrientationInfo
let isPhone = UIDevice.current.userInterfaceIdiom == .phone
var body: some View {
ZStack(alignment: .bottom) {
#if os(iOS)
if isPhone == false && orientationInfo.orientation == .portrait {
FABView()
}
#endif
}
}
}
Run Code Online (Sandbox Code Playgroud)
当 iPad 最初处于横向时,会加载该视图,但当更改为纵向并返回横向时,该视图会被删除。为什么会发生这种情况?如何确保第一次加载时未加载视图?
完整代码
struct HomeTab: View {
var body: some View {
NavigationView …Run Code Online (Sandbox Code Playgroud) 在我的iOS应用程序中,我使用Core Data来存储数据和获取请求以创建NSManagedObject要在a中显示的s 数组UITableView.
在Watch OS上,我检查是否WCSession支持并激活会话,然后从iOS应用程序向watchOS扩展发送消息.
当iOS应用程序从watchOS收到消息时,它应该将数组发送Objects到watchOS扩展中以显示数据WKInterfaceTable,但我不确定如何执行此操作.最终我想要实现的是;
如何Objects与watchOS扩展共享数组?
如果用户在Watch上的数组中添加/编辑/删除对象,我们如何更新iPhone上的数据?
此外,iOS应用程序嵌入在一个内容中,UITabBarController因此与哪个视图控制器进行通信也很重要?
观看OS FavouritesInterfaceController
var session : WCSession!
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
//Check if session is supported and Activate
if (WCSession.isSupported()) {
session = WCSession.defaultSession()
session.delegate = self
session.activateSession()
}
}
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// Interface Objects
//Send Message …Run Code Online (Sandbox Code Playgroud) 所以我一直在尝试使用Core Data和iCloud在两个iDevices之间同步数周.Apple 2012年至2013年的文档是用Objective-C编写的,并不是很详细.
我试图将其转换为适用于iOS9的Swift 2.0.首先我想我可能已经完成了它,两个设备共享数据并同步任何变化.然后事情变得混乱,以前被删除的数据开始出现,同步的唯一方法是重新启动应用程序.现在我遇到了这个错误:
CoreData:Ubiquity:Librarian在开始下载时返回了严重错误Error Domain = BRCloudDocsErrorDomain Code = 6"Path在任何CloudDocs容器之外,永远不会同步"
如果我继续通过Xcode(7)运行应用程序,它似乎确实自我修复并同步更改,但这对现实世界来说并不理想; 用户不必强制退出应用程序并重新启动同步,如果数据已损坏,则重新安装.
有没有人有任何想法,我可能会出错,为什么会出现这种错误?
完全错误:
2015-09-08 22:21:53.679 APPNAME[5550:407392] - [PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](874): CoreData: Ubiquity: nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B:APPNAMEStore
Using local storage: 1 for new NSFileManager current token <766b5e5c 3c205110 52c05248 38a47bd9 aca1ee87>
2015-09-08 22:21:57.639 APPNAME[5550:407392] storesDidChange posting notif
2015-09-08 22:21:57.639 APPNAME[5550:407452] -[PFUbiquitySwitchboardEntryMetadata setUseLocalStorage:](874): CoreData: Ubiquity: nobody~sim73E13D94-AB95-59FB-AF18-ADC7BC05B47B:APPNAMEStore
Using local storage: 0 for new NSFileManager current token <766b5e5c 3c205110 52c05248 38a47bd9 aca1ee87>
2015-09-08 22:21:58.565 APPNAME[5550:407476] __45-[PFUbiquityFilePresenter processPendingURLs]_block_invoke(447): CoreData: Ubiquity: Librarian returned a serious …Run Code Online (Sandbox Code Playgroud) 我正在尝试将3D Touch快捷方式添加到应用程序中,我已经设法在主屏幕上的应用程序图标上使用3DTouch时显示快捷方式; 但是当使用快捷方式时,应用程序在加载时崩溃,我不确定为什么.
我已设法让应用程序加载书签快捷方式,但它没有启动BookmarksViewController,它只是加载InitialViewController.
应用程序嵌入在每个选项卡的a UITabBarController和a UINavigationController中.我试图加载的两个视图控制器都在不同的选项卡中,但导航控制器堆栈中的第一个视图.
有谁知道我哪里出错了?
info.plist文件
App代表
enum ShortcutItemType: String {
case Bookmarks
case Favourites
init?(shortcutItem: UIApplicationShortcutItem) {
guard let last = shortcutItem.type.componentsSeparatedByString(".").last else { return nil }
self.init(rawValue: last)
}
var type: String {
return NSBundle.mainBundle().bundleIdentifier! + ".\(self.rawValue)"
}
}
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
handleShortcutItem(shortcutItem) …Run Code Online (Sandbox Code Playgroud) 我有一个已经使用Core Data的项目.我已经添加了对iPad的支持,但现在需要使用iCloud和Core Data来同步数据.
我遇到了Ensembles,它似乎是一个简单而强大的框架,可以添加到我的项目中.在这里找到:https://github.com/drewmccormack/ensembles
但是,Ensembles项目中没有Swift示例项目,所以我自己试图这样做.以下是我采取的步骤,
步骤1
手动将Ensembles添加到iOS项目中.
第2步
使用现有的持久存储.sql文件创建新的CoreDataStack.
import UIKit
import CoreData
class CoreDataStack: NSObject, CDEPersistentStoreEnsembleDelegate {
static let defaultStack = CoreDataStack()
var ensemble : CDEPersistentStoreEnsemble? = nil
var cloudFileSystem : CDEICloudFileSystem? = nil
// MARK: - Core Data stack
lazy var storeName : String = {
return NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleNameKey as String) as! String
}()
lazy var sqlName : String = {
return "SingleViewCoreData.sqlite"
}()
lazy var icloudStoreName : String = {
return self.storeName + "CloudStore"
}() …Run Code Online (Sandbox Code Playgroud)