我无法将图像快速旋转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) 我使用以下代码将文件保存在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而不是字符串.
问题:
我使用下面的代码在服务器中发出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) 我有用目标编写的代码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)
请告诉我怎么做?
我在 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) 我们有一个集合视图.我制作了一个日历,水平显示日期,我横向滚动日期.现在在屏幕上我只看到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)
请告诉我该如何实现它?
我在我的超级视图中有一个UIView.我已经设置了一些约束.现在我希望视图的大小在不同的设备上应该是不同的.如果我设置了修复宽度和高度,那么我得到错误的结果.我试过用户宽高比,但在多个设备上使视图太大或太小.
我希望高度和宽度应该以相同的比例增加,它必须看起来与所有设备相同.我想要有灵活的视图高度和宽度.请告诉我们如何做到这一点?
这是图像

提前致谢
我有一个自定义单元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)
请告诉我该如何解决这个问题?
ios ×8
swift ×5
arrays ×2
macos ×2
objective-c ×2
uitableview ×2
alamofire ×1
animation ×1
ansible ×1
ansible-2.x ×1
autolayout ×1
chown ×1
cornerradius ×1
iphone ×1
keyboard ×1
macos-sierra ×1
reachability ×1
reloaddata ×1
server ×1
uikeyboard ×1
uiview ×1
xampp ×1
xcode ×1