将新控制器添加到导航堆栈时:
self.navigationController!.pushViewController(PushedViewController(), animated: true)
Run Code Online (Sandbox Code Playgroud)
从右边看:
如何更改动画的方向以使其从左侧显示?
如何使UlCollectionView的项目位于行内左侧
这种位置(上方屏幕截图)只能在线路上有唯一项目的情况下进行; 如果线上有多个元素(项目较小或屏幕较宽),则元素在行内左对齐并且位置看起来像所需:
UICollectionViewFlowLayout的设置如下:
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumLineSpacing = 20.;
flowLayout.minimumInteritemSpacing = 5.;
flowLayout.sectionInset = UIEdgeInsetsMake(23., 15., 23., 15.);
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
self.collectionView.collectionViewLayout = flowLayout;
Run Code Online (Sandbox Code Playgroud) 如何在UISearchController搜索文本字段中更改默认灰色背景?
屏幕截图

在后台模式下播放音频时,播放器控件会出现在锁屏上。音频停止后如何将其删除?如果尝试设置:
MPNowPlayingInfoCenter.default().nowPlayingInfo = nil
Run Code Online (Sandbox Code Playgroud)
播放器仍在锁定屏幕上,但歌手/歌手字段为空
UPD(我的音频会话代码):
在AppDelegate中:
func setupAudioSession() {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayback)
try audioSession.setActive(true)
} catch {
print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
}
Run Code Online (Sandbox Code Playgroud)
在播放器类中:
private func clearRemotePlayerInfo() { // call after stop button pressed
try? AVAudioSession.sharedInstance().setActive(false)
MPNowPlayingInfoCenter.default().nowPlayingInfo = [:]
}
Run Code Online (Sandbox Code Playgroud) 我知道可以使用分别为«大»和«小»标题设置字体系列,字体大小和颜色prefersLargeTitles。
问题是:导航控制器是否有任何选项可以在打开的带有大写字母的导航面板中显示“大标题”?
现在,我使用自定义导航控制器:
class MyNavigationController: UINavigationController {
public var titleSaved: String?
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
guard let topItem = navigationBar.topItem else {
return
}
if navigationBar.frame.size.height > 60 {
topItem.title = topItem.title?.uppercased()
} else {
if let titleSaved = titleSaved {
topItem.title = titleSaved
} else {
topItem.title = topItem.title?.applyingTransform(StringTransform(rawValue: "Title"), reverse: false)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
从视图控件设置标题:
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.prefersLargeTitles = true
let title = "Sign In"
navigationItem.title = …Run Code Online (Sandbox Code Playgroud)