我已经研究了很多这个问题,但我找不到适用于我的解决方案。
基本上,我有#include <iostream>
#include <Windows.h>
#include <fstream>
#include <shlobj.h> // Needed to use the SHGetFolderPath function.
using namespace std;
bool GetDesktopfilePath(PTCHAR filePath, PTCHAR fileName)
{
// Get the full path of the desktop :
if (FAILED(SHGetFolderPath(NULL,
CSIDL_DESKTOPDIRECTORY | CSIDL_FLAG_CREATE,
NULL,
SHGFP_TYPE_CURRENT,
filePath))) // Store the path of the desktop in filePath.
return false;
SIZE_T dsktPathSize = lstrlen(filePath); // Get the size of the desktope path.
SIZE_T fileNameSize = lstrlen(fileName); // Get the size of the file name.
// Appending the fileName to the filePath :
memcpy((filePath + dsktPathSize), fileName, (++fileNameSize * sizeof(WCHAR)));
return true;
}
int main()
{
ofstream myFile;
TCHAR filePath[MAX_PATH]; // To store the path of the file.
TCHAR fileName[] = L"\\Textfile.txt"; // The file name must begin with "\\".
GetDesktopfilePath(filePath, fileName); // Get the full path of the file situated in the desktop.
myFile.open(filePath); // Opening the file from the generated path.
myFile << "Writing this to a file" << endl;
myFile.close();
return 0;
}
这样的UIViewController
:
UISearchController
然后,用户需要点按let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.delegate = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.delegate = self
view.addSubview(searchController.searchBar)
以显示UISearchBar
并显示键盘。但是,在控制器之间的过渡期间发生了一件奇怪的事情。
似乎searchController
没有覆盖状态栏,让您看到下面显示的UISearchController
。 我想找到一种方法来阻止这种情况,即强制搜索控制器一直延伸到状态栏下。
我已经做过的事情:
UIViewController
中设置了self.definesPresentationContext = true
。我试图通过设置:
来规避错误viewDidLoad:
它没有用。
我的想法已经不多了。请帮忙。
非常感谢, 皮特。
答案 0 :(得分:0)
面对同样的问题并尝试了here和here的所有内容,但这些都不适合我:(
在我找到更好的解决方案之前,最好的解决方法(我知道很难看):
override func viewDidLoad() {
super.viewDidLoad()
searchController.delegate = self
}
func willPresentSearchController(searchController: UISearchController) {
let statusHeight = UIApplication.sharedApplication().statusBarFrame.size.height
if bgBar == nil {
bgBar = UIView(frame: CGRectMake(0, 0, view.frame.width, (navigationController?.navigationBar.frame.height)! + statusHeight))
bgBar.backgroundColor = UIColor.redColor()
view.addSubview(bgBar)
} else {
bgBar.hidden = false
}
tableView.contentInset.top = statusHeight
}
func willDismissSearchController(searchController: UISearchController) {
bgBar.hidden = true
tableView.contentInset.top = 0
}
答案 1 :(得分:0)
在swift 4:
viewWillAppear(_ animated: Bool) {
let statusHeight = UIApplication.shared.statusBarFrame.size.height
let sbview = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: statusHeight))
sbview.backgroundColor = .white
view.addSubview(sbview)
{