小编Tec*_*ain的帖子

如何在Swift中旋转图像?

我无法将图像快速旋转90度.我写了下面的代码,但有一个错误,不编译

  func imageRotatedByDegrees(oldImage: UIImage, deg degrees: CGFloat) -> UIImage {

    //Calculate the size of the rotated view's containing box for our drawing space
    let rotatedViewBox: UIView = UIView(frame: CGRect(x: 0, y: 0, width: oldImage.size.width, height: oldImage.size.height))
    let t: CGAffineTransform = CGAffineTransform(rotationAngle: degrees * CGFloat(M_PI / 180))
    rotatedViewBox.transform = t
    let rotatedSize: CGSize = rotatedViewBox.frame.size

    //Create the bitmap context
    UIGraphicsBeginImageContext(rotatedSize)
    let bitmap: CGContext = UIGraphicsGetCurrentContext()!

    //Move the origin to the middle of the image so we will rotate and scale around …
Run Code Online (Sandbox Code Playgroud)

animation uiview uiviewanimation ios swift

45
推荐指数
7
解决办法
7万
查看次数

如何在IOS键盘顶部的键盘上添加完成按钮?

我想Done在iOS右侧的键盘顶部添加按钮,用于textView.请告诉我该怎么做?

在此输入图像描述

我想实现与上述键盘类似的东西

keyboard objective-c uikeyboard ios

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

将文件保存在swift 3的文档目录中?

我使用以下代码将文件保存在swift 3的文档目录中:

fileManager = FileManager.default
// let documentDirectory = fileManager?.urls(for: .documentDirectory, in: .userDomainMask).first as String
var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
path = path + name

let image = #imageLiteral(resourceName: "Notifications")
let imageData = UIImageJPEGRepresentation(image, 0.5)
let bool = fileManager?.createFile(atPath: path, contents: imageData, attributes: nil)

print("bool is \(bool)")
return true
Run Code Online (Sandbox Code Playgroud)

但正如您所看到的,我不是filemanager用来获取文档目录路径,因为filemanager只提供URL而不是字符串.

问题:

  • 如何从文件管理器中获取字符串?
  • 我的代码中是否有崩溃的可能性?

nsfilemanager ios nsdocumentdirectory swift

25
推荐指数
3
解决办法
5万
查看次数

如何检查alamofire中的互联网连接?

我使用下面的代码在服务器中发出HTTP请求.现在我想知道它是否连接到互联网.以下是我的代码

  let request = Alamofire.request(completeURL(domainName: path), method: method, parameters: parameters, encoding: encoding.value, headers: headers)
      .responseJSON {


        let resstr = NSString(data: $0.data!, encoding: String.Encoding.utf8.rawValue)
        print("error is \(resstr)")


        if $0.result.isFailure {
          self.failure("Network")
          print("API FAILED 4")
          return
        }
        guard let result = $0.result.value else {
          self.unKnownError()
          self.failure("")
          print("API FAILED 3")

          return
        }
        self.handleSuccess(JSON(result))
    }
Run Code Online (Sandbox Code Playgroud)

reachability ios swift alamofire

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

在swift 3中重新加载部分方法?

我有用目标编写的代码cI想要将此代码转换为swift3代码.

[_expandableTableView reloadSections:[NSIndexSet indexSetWithIndex:gestureRecognizer.view.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
Run Code Online (Sandbox Code Playgroud)

使用在线工具转换后,它给了我下面的代码,但它不起作用

expandableTableView.reloadSections(IndexSet(index: gestureRecognizer.view!.tag), with: .automatic)
Run Code Online (Sandbox Code Playgroud)

请告诉我怎么做?

arrays uitableview reloaddata ios swift

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

在ansible中使用chown命令?

我在 ubuntu 中有一个命令

  sudo chown $(id -u):$(id -g) $HOME/.kube/config 
Run Code Online (Sandbox Code Playgroud)

我想转换成ansible脚本。我在下面试过

- name: Changing ownership
      command: chown $(id -u):$(id -g) $HOME/.kube/config
      become: true 
Run Code Online (Sandbox Code Playgroud)

但我收到如下错误

致命:[ubuntu]:失败!=> {“已更改”:t> 致命:[ubuntu]:失败!=> {"changed": true, "cmd": ["chown", "$(id", "-u):$(id", "-g)", "$HOME/.kube/config"] , "delta": "0:00:00.003948", "end": "2019-07-17 07:22:31.798773", "msg": "非零返回码", "rc": 1, "start ": "2019-07-17 07:22:31.794825", "stderr": "chown: invalid option -- 'u'\nTry 'chown --help' 了解更多信息。", "stderr_lines": ["chown : 无效选项 -- 'u'", "Try 'chown --help' 了解更多信息。"], "stdout": "", "stdout_lines": []}rue, "cmd": ["chown",

编辑: 文件模块也不起作用。

  - name: Create a symbolic …
Run Code Online (Sandbox Code Playgroud)

chown ansible ansible-2.x

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

如何在swift中滚动到集合视图中的特定元素索引

我们有一个集合视图.我制作了一个日历,水平显示日期,我横向滚动日期.现在在屏幕上我只看到3-4个日期.现在我想在我显示的日历屏幕时自动滚动到特定的选定日期.所以我想要滚动到的日期还不可见.

为此,我获得了特定单元格的索引路径.现在我试图将其滚动到特定的索引路径.

  func scrollCollectionView(indexpath:IndexPath)
  {
   // collectionView.scrollToItem(at: indexpath, at: .left, animated: true)
    //collectionView.selectItem(at: indexpath, animated: true, scrollPosition: .left)
    collectionView.scrollToItem(at: indexpath, at: .centeredHorizontally, animated: true)
    _ = collectionView.dequeueReusableCell(withReuseIdentifier: "DayCell", for: indexpath) as? DayCell

  }
Run Code Online (Sandbox Code Playgroud)

请告诉我该如何实现它?

arrays iphone ios uicollectionview swift

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

无法在xammp上找到htdoc?

我为macOS Sierra安装了XAMPP.我在申请XAMPP时有一个图标.我能够运行服务器及其服务,但我无法找到该htdocs文件夹.

我没有找到它 \Library\Webserver

在此输入图像描述

在此输入图像描述

xampp macos server macos-sierra

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

如何在iOS中的autolayout中设置视图的动态宽度和高度?

我在我的超级视图中有一个UIView.我已经设置了一些约束.现在我希望视图的大小在不同的设备上应该是不同的.如果我设置了修复宽度和高度,那么我得到错误的结果.我试过用户宽高比,但在多个设备上使视图太大或太小.

我希望高度和宽度应该以相同的比例增加,它必须看起来与所有设备相同.我想要有灵活的视图高度和宽度.请告诉我们如何做到这一点?

这是图像 在此输入图像描述

提前致谢

macos xcode objective-c ios autolayout

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

在单元格内设置视角半径的问题?

我有一个自定义单元UITableView格.我设置它的左下角和右下角半径.我正在设置角半径cellForAtindexPath.Below是代码

  if indexPath.row == 9 {

    recipeInfoCell.outerView.roundCorners(corners: [.bottomLeft, .bottomRight], radius: 10)
    recipeInfoCell.layoutSubviews()
    recipeInfoCell.layoutIfNeeded()
  }
  else  {

    recipeInfoCell.outerView.roundCorners(corners: [.bottomLeft, .bottomRight], radius: 0)
    recipeInfoCell.layoutSubviews()


  }
Run Code Online (Sandbox Code Playgroud)

现在,当我第一次启动tableview时,它没有设置任何角半径.但是当我再次滚动时,它正在设置角半径.

我创建了一个扩展,UIView其中有一个功能是设置角半径

  func roundCorners(corners:UIRectCorner, radius: CGFloat) {

    let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
    let mask = CAShapeLayer()
    mask.path = path.cgPath
    self.layer.mask = mask
  }
Run Code Online (Sandbox Code Playgroud)

请告诉我该如何解决这个问题?

cornerradius uitableview tableviewcell ios

12
推荐指数
3
解决办法
2627
查看次数