小编jmc*_*tel的帖子

滚动时隐藏状态栏

iOS 8增加了一个超酷的新功能:在用户滚动时隐藏导航栏.

这有一行viewDidload:

navigationController?.hidesBarsOnSwipe = true
Run Code Online (Sandbox Code Playgroud)

很酷,不是吗?

但是现在我遇到了一个小问题:当隐藏导航栏时,状态栏仍然在这里并重叠内容,这很难看.

隐藏导航栏时,我该怎么做才能隐藏它?

statusbar ios swift ios8

19
推荐指数
2
解决办法
9503
查看次数

如何使用indexPathsForSelectedItems在集合视图中获取所选项

我有一个照片集合视图,想要将照片传递给一个detailViewControler.

收集数据来自:

 var timeLineData:NSMutableArray = NSMutableArray ()
Run Code Online (Sandbox Code Playgroud)

我想使用准备segue方法.

我的问题是如何从被单击的单元格中获取好的indexPath?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue == "goToZoom" {
        let zoomVC : PhotoZoomViewController = segue.destinationViewController as PhotoZoomViewController
        let cell = sender as UserPostsCell

        let indexPath = self.collectionView!.indexPathForCell(cell)
        let userPost  = self.timeLineData.objectAtIndex(indexPath!.row) as PFObject
        zoomVC.post = userPost

    }
} 
Run Code Online (Sandbox Code Playgroud)

nsindexpath ios uicollectionview swift

18
推荐指数
3
解决办法
4万
查看次数

如何从appDelegate呈现UIAlertView

当应用程序收到推送通知时,我试图在didReceiveRemoteNotification中显示来自appDelegate的UIAlertView.

我有这个错误:

  Warning: Attempt to present <UIAlertController: 0x14c5494c0> on <UINavigationController:
  0x14c60ce00> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: NSDictionary) {

    var contentPush: NSDictionary = userInfo.objectForKey("aps") as NSDictionary

    var message = contentPush.objectForKey("alert") as String



    let alertController = UIAlertController(title: "Default Style", message: message, preferredStyle: .Alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
                    // ...
    }
    alertController.addAction(cancelAction)

    let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in

        let photoPushedVc = self.storyboard.instantiateViewControllerWithIdentifier("CommentTableViewController") as CommentTableViewController …
Run Code Online (Sandbox Code Playgroud)

view ios swift

14
推荐指数
5
解决办法
2万
查看次数

Swift:键盘显示时向上滚动视图

我有一个scrollView,我想在键盘显示时向上滚动.

当键盘显示时,我遇到此错误:

2014年9月29日14:48:50.738 SWRD [1563:472888] - [swrd.EditPhotoViewController keyboardWasShown]:无法识别的选择发送到实例0x14ed36640

这是我的代码,出了什么问题?:

   func registerForKeyboardNotifications ()-> Void   {

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown", name: UIKeyboardDidShowNotification, object: nil)

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillBeHidden", name: UIKeyboardWillHideNotification, object: nil)


}

func deregisterFromKeyboardNotifications () -> Void {
    let center:  NSNotificationCenter = NSNotificationCenter.defaultCenter()
    center.removeObserver(self, name: UIKeyboardDidHideNotification, object: nil)
    center.removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)


}


 func keyboardWasShown (notification: NSNotification) {

    let info : NSDictionary = notification.userInfo!
    let keyboardSize = info.objectForKey(UIKeyboardFrameBeginUserInfoKey)?.frame

    let insets: UIEdgeInsets = UIEdgeInsetsMake(self.scrollView.contentInset.top, 0, keyboardSize!.height, 0)

    self.scrollView.contentInset = insets
    self.scrollView.scrollIndicatorInsets = insets …
Run Code Online (Sandbox Code Playgroud)

keyboard scrollview ios swift

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

使用swift更改拉动以刷新文本颜色

我在我的应用程序中刷新了一下.

如何更改attributionTitle的文本颜色?

 refresher.attributedTitle = NSAttributedString(string: "hey ! is there something new ?")
Run Code Online (Sandbox Code Playgroud)

colors pull-to-refresh swift

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

斯威夫特:从AVFoundation拍照

我想将这个函数从obj c转换为swift,buti无法翻译部分代码.有人可以解释我如何从AVFondation拍照或帮我翻译这个功能?

- (void) capImage { //method to capture image from AVCaptureSession      video feed
     AVCaptureConnection *videoConnection = nil;
     for (AVCaptureConnection *connection in stillImageOutput.connections) {

  for (AVCaptureInputPort *port in [connection inputPorts]) {

  if ([[port mediaType] isEqual:AVMediaTypeVideo] ) {
    videoConnection = connection;
        break;
  }
  }

   if (videoConnection) {
    break;
 }
}

 NSLog(@"about to request a capture from: %@", stillImageOutput);
[stillImageOutput     captureStillImageAsynchronouslyFromConnection:videoConnection          completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {

  if (imageSampleBuffer != NULL) {
   NSData *imageData = [AVCaptureStillImageOutput        jpegStillImageNSDataRepresentation:imageSampleBuffer];
[self processImage:[UIImage imageWithData:imageData]];
 }
}]; …
Run Code Online (Sandbox Code Playgroud)

avfoundation ios swift

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

添加子视图控制器swift

我试图将子视图控制器添加到containerViewController

孩子是:

AViewController
BViewController
CViewController
Run Code Online (Sandbox Code Playgroud)

我没有错误但是当我启动应用程序时,我可以刷屏幕,有3个部分刷,但A,B,C视图控制器没有出现..

这是我的代码,任何想法?

import UIKit

class ContainerViewController: UIViewController {

@IBOutlet var scrollView: UIScrollView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.


    // creat VC

    var Avc : AViewController = AViewController ()
    var Bvc : BViewController = BViewController ()
    var Cvc : CViewController = CViewController ()



    // add it to the view hierarchie


    self.addChildViewController(Cvc)
    self.scrollView.addSubview(Cvc.view)
    Cvc.didMoveToParentViewController(self)

    self.addChildViewController(Bvc)
    self.scrollView.addSubview(Bvc.view)
    Bvc.didMoveToParentViewController(self)


    self.addChildViewController(Avc)
    self.scrollView.addSubview(Avc.view)
    Avc.didMoveToParentViewController(self)

    // set the frame

    var …
Run Code Online (Sandbox Code Playgroud)

controller view ios swift

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

Swift:隐藏子视图中的按钮

我试图在触发函数时隐藏子视图中的UIButton.我有这个层次结构的多个视图:

  var takePhotoButton : UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton

        takePhotoButton.addTarget(self, action:"takePhoto", forControlEvents:UIControlEvents.TouchUpInside)


        var savePhotoButton : UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton


        let view2:UIView = UIView(frame: CGRectMake(0, 0, 320, 568))


        self.view.addSubview(photoMask)
        photoMask.addSubview(view2)
        view2.addSubview(takePhotoButton)
Run Code Online (Sandbox Code Playgroud)

我想在触发下面的func时隐藏takePhotoButton,我怎么能这样做?

     func takePhoto(takePhotoButton: UIButton!) {
   takePhotoButton.hidden = true
   }
Run Code Online (Sandbox Code Playgroud)

button subview ios swift

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

Parse.com NSURLErrorDomain Code = -1003 in cellular in wireless

我有一个与parse.com后端一起使用的应用程序.从今天起,NSURLErrorDomain Code = -1003,parse.com仅使用蜂窝网络.Wifi工作得很好.可能是什么问题 ?

这里是完整的错误:

    [Error]: Error Domain=NSURLErrorDomain Code=-1003  
    "A server with the specified hostname could not be found." 
    UserInfo=0x1700f2200{NSUnderlyingError=0x170245880 "A server with the specified hostname could not be found.",
    NSErrorFailingURLStringKey=https://api.parse.com/2/find, 
    NSErrorFailingURLKey=https://api.parse.com/2/find, 
    _kCFStreamErrorDomainKey=12, 
    _kCFStreamErrorCodeKey=8, 
    NSLocalizedDescription=A server with the specified hostname could 
    not be    found.} 
    (Code: 100, Version: 1.6.1)
Run Code Online (Sandbox Code Playgroud)

nsurlconnection ios parse-platform

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