当有人动摇iPhone时,我想做出反应.我并不特别在乎它们是如何摇晃它的,只是它在一瞬间大力挥手.有谁知道怎么检测到这个?
我想从appdelegate设置初始viewcontroller.我找到了一个非常好的答案,但它是在Objective C中,我很难在swift中实现同样的功能.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *viewController = // determine the initial view controller here and instantiate it with [storyboard instantiateViewControllerWithIdentifier:<storyboard id>];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
有人能帮忙吗?
我希望初始Viewcontroller依赖于使用条件语句满足的某些条件.
我想在UITableView上实现一个捏合/外出,我已经看了几个方法,包括这个:
但是虽然我可以创建一个UIViewTouch对象并将其覆盖到我的UITableView上,滚动事件不会被转发到我的UITableView,我仍然可以选择单元格,并且它们通过触发转换到新的ViewController对象来正确响应.但是,尽管传递了touchesBegan,touchesMoved和touchesEnded事件,但我无法滚动UITableView.
我在这里有一个关于故事板的通用项目.我创建了一个名为MyWindow的UIWindow子类,我需要加载它而不是默认的UIWindow.在故事板之前,我只需要转到XCode中的.XIB文件,然后将主窗口的类更改为MyWindow.但是,我无法找到任何可以在故事板中更改此内容的部分.
有谁知道我能做到这一点?我需要主窗口加载MyWindow,而不是UIWindow.
如何在Swift中的AppDelegate(整个应用程序)中检测到设备震动?
我找到了解释如何在视图控制器中执行此操作的答案,但希望在我的应用程序中执行此操作.
UITouchEvent,相位Began,它调用touchesBegan:withEvent:在方法controllerA,其中从执行SEGUE controllerA到controllerB.UITouchEvent,相位Ended,它调用一些回调方法.问题:此回调方法的内容和位置是什么?它不在controllerA,它不在controllerB.据我所知,这不是任何观点.但它存在.
我正在尝试为我正在使用Swift 2开发的应用程序创建超时功能,但在swift 2中,您可以将此代码放在应用程序委托中并且它可以工作,但它不会检测到任何键盘按下,按钮按下,文本字段按下, 等等:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event);
let allTouches = event!.allTouches();
if(allTouches?.count > 0) {
let phase = (allTouches!.first as UITouch!).phase;
if(phase == UITouchPhase.Began || phase == UITouchPhase.Ended) {
//Stuff
timeoutModel.actionPerformed();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在swift 2之前,我能够拥有AppDelegate子类UIApplication并覆盖sendEvent:像这样:
-(void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];
// Only want to reset the timer on a Began touch or an Ended touch, to reduce the number of timer resets.
NSSet *allTouches = [event allTouches];
if ([allTouches count] > …Run Code Online (Sandbox Code Playgroud) ios ×5
iphone ×3
appdelegate ×2
shake ×2
multi-touch ×1
objective-c ×1
pinch ×1
storyboard ×1
subclass ×1
swift ×1
swift2 ×1
swift3 ×1
timeout ×1
touch ×1
uitableview ×1
uiwindow ×1
xcode ×1