Skip to content

Instantly share code, notes, and snippets.

@sawat
sawat / SafariWrapperViewController.swift
Last active October 16, 2015 02:48
遷移元のdispearでナビゲーションバーを消す場合、【遷移先がSafariVCか確認する必要がある】【遷移元VCが複数になるとコードが散らばる】という問題があるので、以下のようなSafariVCのラッパーを使う方が良さそうです。
import UIKit
import SafariServices
class SafariWrapperViewController: UIViewController {
var safariViewController:SFSafariViewController? {
didSet(old) {
if old == self.safariViewController {
return
}
@sawat
sawat / SampleViewController.swift
Last active October 16, 2015 01:24
UINavigationControllerの子VCからSFSafariViewControllerをプッシュして表示する。その際にナビゲーションバーのalphaを0にすることで、SFSafariViewControllerのナビゲーションバーを使用可能な状態にしつつ、エッジスワイプで遷移元に戻れるようにする。ただし、このコードではviewWillDisappearでナビゲーションバーを消しているので、SFSafariViewController以外のVCに遷移するときもナビゲーションバーを消してしまうので注意。
import UIKit
import SafariServices
class SampleViewController: UIViewController, SFSafariViewControllerDelegate {
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.alpha = 1.0
}
@sawat
sawat / avoid_crash_on_ja_text_input.m
Created October 11, 2012 03:04
[iOS6]日本語入力中にロックでクラッシュする件の回避策(ウチのアプリはこれでクラッシュしなくなった)
@property (nonatomic, weak) UIResponder *maybeFirstResponder;
// ...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// UITextFieldTextDidBeginEditingNotificationを対象オブジェクトnilで監視
[[NSNotificationCenter defaultCenter] addObserverForName:UITextFieldTextDidBeginEditingNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
// イベント発生元オブジェクトを弱参照で保持しておく
self.maybeFirstResponder = note.object;