我正在使用presentViewController来呈现新的屏幕
let dashboardWorkout = DashboardWorkoutViewController()
presentViewController(dashboardWorkout, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
这从底部到顶部呈现新屏幕,但我希望它从右到左呈现而不使用UINavigationController.
我使用Xib而不是故事板,所以我该怎么做?
我有一个从底部UIViewController只UIView覆盖viewController的1/3.像这样
我想在另一个ViewController上呈现这个viewController.它应该从底部动画出现,它应该忽略到底部动画.
但我不希望它覆盖整个屏幕.显示它的viewController应该在后面可见.
这似乎是一个基本问题但我无法完成它.有人可以指点我的方向吗?
编辑:
这就是我迄今为止所尝试过的.我创建了这些类
// MARK: -
class MyFadeInFadeOutTransitioning: NSObject, UIViewControllerTransitioningDelegate {
var backgroundColorAlpha: CGFloat = 0.5
var shoulDismiss = false
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let fadeInPresentAnimationController = MyFadeInPresentAnimationController()
fadeInPresentAnimationController.backgroundColorAlpha = backgroundColorAlpha
return fadeInPresentAnimationController
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let fadeOutDismissAnimationController = MyFadeOutDismissAnimationController()
return fadeOutDismissAnimationController
}
}
// MARK: -
class MYFadeInPresentAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
let kPresentationDuration = 0.5
var backgroundColorAlpha: CGFloat?
func transitionDuration(using …Run Code Online (Sandbox Code Playgroud) 我创建了一个UIProgressView具有以下属性
progressView.progressTintColor = UIColor.appChallengeColorWithAlpha(1.0)
progressView.trackTintColor = UIColor.clearColor()
progressView.clipsToBounds = true
progressView.layer.cornerRadius = 5
Run Code Online (Sandbox Code Playgroud)
我正在使用UIView边框.看起来他的进步= 1,这正是我想要的方式.
但是,如果进度值小于1.角落不应该是圆形的.
我错过了什么吗?我怎样才能圆角呢?
我正在将我的项目从Swift 2.3迁移到Swift 3.并且遇到了预期的困难.
这是一个使用OAuthSwift用于OAuth的函数.我试过转换
class func OAuthSwiftAuthorization(inViewController viewController: UIViewController, withOAuthInfo info:FitnessTracker, successHandler:@escaping MyOAuthNewSuccessHandler, failure: @escaping ((_ error: NSError) -> Void)) {
let oauthswift = OAuth2Swift(
consumerKey: info.consumerKey,
consumerSecret: info.consumerSecret,
authorizeUrl: info.authorizeUrl,
accessTokenUrl: info.accessTokenUrl,
responseType: info.responseType
)
oauthswift.authorizeURLHandler = SafariURLHandler(viewController: viewController, oauthSwift: oauthswift)
oauthswift.accessTokenBasicAuthentification = true
oauthswift.allowMissingStateCheck = true
oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
successHandler(credential, response, parameters)
}) { (error) in
failure(error: error)
print(error.localizedDescription)
}
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误
oauthswift.authorize(withCallbackURL: URL(string: …Run Code Online (Sandbox Code Playgroud) 我试过这种方法
@IBAction func handlePan(recognizer:UIPanGestureRecognizer) {
let translation = recognizer.translationInView(self.view)
if let view = recognizer.view {
view.center = CGPoint(x:view.center.x + translation.x,
y:view.center.y + translation.y)
}
recognizer.setTranslation(CGPointZero, inView: self.view)
}
Run Code Online (Sandbox Code Playgroud)
它工作但问题是,当我在多个图像上使用此方法时,它会产生一些问题,例如,拖动一个图像并更改其位置但是当我单击并拖动第二个图像时.我的第一张照片回到原来的位置.以下是我从滚动视图中获取的图像:当我点击第二张图像时,第一张图像也会转到原始位置
我在这里拖动图像很好
我被困在一次更新 300 多个联系人的问题上。当我尝试将真实联系人的 mutablecontact 图像更新为 mutablablecopy 时,发生内存泄漏。
RAM 使用量超过 1.4GB,然后应用程序崩溃。这是我的代码。
if let mutableCopy = contact.mutableCopy() as? CNMutableContact {
ImageDownloader.default.downloadImage(with: URL(string: thumbnailImageURL)!) { result in
switch result {
case .success(let value):
queue.sync {
SVProgressHUD.show(withStatus: "loading 1")
//mutableCopy.imageData = compressedImage?.pngData()
mutableCopy.imageData = value.image.pngData() //self.returnCustomSizeImage(image: value.image).pngData()
mutableCopy.givenName = givenName
mutableCopy.phoneNumbers = [CNLabeledValue(label: self.responsedContactsArray[index2].label ?? "NO DOB", value: CNPhoneNumber(stringValue: "\(trimmedPhoneNumber)"))]
//mutableCopy.familyName = "?"
saveRequest.update(mutableCopy)
do {
try AppDelegate.mContactStore.execute(saveRequest)
} catch let error {
SVProgressHUD.dismiss()
}
}
Run Code Online (Sandbox Code Playgroud) 首先,我在https://www.fitbit.com创建了一个帐户 ,然后我在https://dev.fitbit.com上创建了一个应用程序 ,然后使用 cocoa pod 安装了OAuthSwift,并在我的 AppDelegate 中实现了此方法
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
if (url.host == "oauth-callback") {
OAuthSwift.handleOpenURL(url)
}
return true
}
Run Code Online (Sandbox Code Playgroud)
现在我想获取我在https://www.fitbit.com创建的用户帐户的数据(名称、采取的步骤等),
我该怎么做?我进行了搜索,但找不到任何有关 Fitbit 集成的教程。以及在我的代码中哪里使用这些信息?
因此,请指导我下一步应该做什么来获取数据。
我刚刚更新到Xcode 8,现在我收到了项目中的错误
类型'NSObject'没有成员'copy'.
在升级Xcode之前,我没有收到此错误.
注意:我还在使用Swift 2.3.我将UILabel子类化,以便我可以允许用户在长按上复制标签上的文本.以下是我的代码.该行发生错误:
if action == #selector(NSObject.copy(_:))
Run Code Online (Sandbox Code Playgroud)
这是完整的代码:
class MCCopyableLabel: UILabel {
override init(frame: CGRect) {
super.init(frame: frame)
sharedInit()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
sharedInit()
}
func sharedInit() {
userInteractionEnabled = true
addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(MCCopyableLabel.showMenu(_:))))
}
func showMenu(sender: AnyObject?) {
becomeFirstResponder()
let menu = UIMenuController.sharedMenuController()
if !menu.menuVisible {
menu.setTargetRect(bounds, inView: self)
menu.setMenuVisible(true, animated: true)
}
}
override func copy(sender: AnyObject?) {
let board = UIPasteboard.generalPasteboard()
board.string = text
let menu = UIMenuController.sharedMenuController() …Run Code Online (Sandbox Code Playgroud) 我躲在我的状态栏上的特定viewController使用
override func prefersStatusBarHidden() -> Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
直到我在屏幕上显示警报之前,它的工作都非常好。当出现警报时,状态栏再次出现,这是我不想要的。解除警报后,状态栏将再次隐藏。
我正在swift构建一个iOS应用程序,客户端返回了录音的问题,基本上它没有记录任何内容.他在带有ios 9.x的iPhone 5/5s上进行了测试.检查权限,如果手机上有足够的空间,这些都不是问题.
就个人而言,在模拟器上使用带有ios 10.x和iphone 5的iphone 6s设备测试并且记录正在运行.任何人之前遇到过这种情况,或者说我做错了什么让我望而却步.
为不同的功能添加了注释,说明应用程序的功能.
protocol RecordAndPlayManagerDelegate : class{
func recorderDidStopRecording()
}
class RecordAndPlayManager: NSObject, AVAudioRecorderDelegate {
var soundRecorder: AVAudioRecorder!
let recordSettings = [
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
AVSampleRateKey: 12000,
AVNumberOfChannelsKey: 1,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]
class func directoryURL() -> URL? {
let fileManager = FileManager.default
let urls = fileManager.urls(for: .documentDirectory, in: .userDomainMask)
let documentDirectory = urls[0] as URL
let soundURL = documentDirectory.appendingPathComponent("recording.m4a")
return soundURL
}
//calling this from outside to get the audio
class func getLocalOrRemoteRecording(_ recordingID : String!) …Run Code Online (Sandbox Code Playgroud)