因此,numpad键盘默认没有"完成"或"下一步"按钮,所以我想添加一个.在iOS 6及更低版本中,有一些技巧可以在键盘上添加一个按钮,但它们似乎不适用于iOS 7.
首先,我订阅显示通知的键盘
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)
然后我尝试在键盘出现时添加一个按钮:
- (void)keyboardWillShow:(NSNotification *)note
{
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
doneButton.frame = CGRectMake(0, 50, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(dismissKeyboard) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)
[keyboard addSubview:doneButton]; …
Run Code Online (Sandbox Code Playgroud) 在iOS9之前,我们创建了一个类似的目录
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
let logsPath = documentsPath.stringByAppendingPathComponent("logs")
let errorPointer = NSErrorPointer()
NSFileManager.defaultManager().createDirectoryAtPath(logsPath, withIntermediateDirectories: true, attributes: nil, error: errorPointer)
Run Code Online (Sandbox Code Playgroud)
但是对于iOS9,他们删除了String.stringByAppendingPathComponent.自动转换工具取代了我们对NSURL使用String.createDirectoryAtPath()接受一个字符串,所以我需要将NSURL转换为字符串.我们像这样使用absolutePath :(更新为iOS9)
let documentsPath = NSURL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0])
let logsPath = documentsPath.URLByAppendingPathComponent("logs")
do {
try NSFileManager.defaultManager().createDirectoryAtPath(logsPath.absoluteString, withIntermediateDirectories: true, attributes: nil)
} catch let error as NSError {
NSLog("Unable to create directory \(error.debugDescription)")
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
无法创建目录错误Domain = NSCocoaErrorDomain Code = 513"您无权将文件"logs"保存在"Documents"文件夹中." UserInfo = {NSFilePath = file:/// var/mobile/Containers/Data/Application/F2EF2D4F-94AF-4BF2-AF9E-D0ECBC8637E7/Documents/logs /,NSUnderlyingError = 0x15664d070 {Error Domain = NSPOSIXErrorDomain Code = …
在MVVM WPF应用程序中.
你如何设置第二个Windows父级ViewModel
?
例:
view1
- viewModel1
viewModel1
的命令调用:
var view2 = new view2
Run Code Online (Sandbox Code Playgroud)
view2.Owner
= <----这是问题所在.如何从这里获取view1作为所有者viewModel
?
view2.Show()
Run Code Online (Sandbox Code Playgroud)
编辑:
请参阅下面接受的答案,然后阅读以下编辑内容.
我正在使用MVVM灯 - > http://mvvmlight.codeplex.com/ (真棒顺便说一句)
烘焙消息传递系统非常棒.我现在正在从viewmodel向我的视图发送一条消息,告诉它显示另一个窗口.
对于消息我当前在主视图中使用带有switch语句的字符串来确定要打开的视图; 但是我可能会修改也是MVVM light toolkit一部分的令牌.
谢谢!
如何获得UIImage
的SKTexture
?
我试图让UIImage
从SKTextureAtlas
,但似乎不是工作压力太大:
// p40_prop1 is a part of SKTextureAtlas
UIImage *image = [UIImage imageNamed:@"p40_prop1"];
Run Code Online (Sandbox Code Playgroud)
image
没有.
我正在尝试从Swift 1.2更改为Swift 2.0,而我正处于更改的末尾.目前我正在对MapViewController进行更改,并且没有任何错误或警告,但我的pin(annotationView)的自定义图像没有分配给引脚,而是显示默认值(红点).
这是我的代码,我希望你能帮助我一些提示,因为我认为一切都很好,但它仍然无法正常工作:
func parseJsonData(data: NSData) -> [Farmacia] {
let farmacias = [Farmacia]()
do
{
let jsonResult = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as? NSDictionary
// Parse JSON data
let jsonProductos = jsonResult?["farmacias"] as! [AnyObject]
for jsonProducto in jsonProductos {
let farmacia = Farmacia()
farmacia.id = jsonProducto["id"] as! String
farmacia.nombre = jsonProducto["nombre"] as! String
farmacia.location = jsonProducto["location"] as! String
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString(farmacia.location, completionHandler: { placemarks, error in
if error != nil {
print(error)
return
}
if placemarks != …
Run Code Online (Sandbox Code Playgroud) 我有以下代码用于测试目的:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self customTouchHandler:touches];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self customTouchHandler:touches];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self customTouchHandler:touches];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self customTouchHandler:touches];
}
- (void)customTouchHandler:(NSSet *)touches
{
for(UITouch* touch in touches){
if(touch.phase == UITouchPhaseBegan)
touchesStarted++;
if(touch.phase == UITouchPhaseEnded || touch.phase == UITouchPhaseCancelled)
touchesFinished++;
}
NSLog(@"%d / %d", touchesStarted, touchesFinished);
}
Run Code Online (Sandbox Code Playgroud)
我想当屏幕上没有触摸时,touchesStarted
应该总是等于touchesFinished
,但我有一个非常奇怪的输出:
2014-04-16 13:44:27.780 App[5925:60b] 2 / 0
2014-04-16 13:44:27.911 App[5925:60b] 2 / …
Run Code Online (Sandbox Code Playgroud) 在Swift中,UIControl
似乎没有setEnabled:
方法.有没有办法检测控制状态何时发生变化?
我有以下课程:
class BaseCache<T: Equatable>: NSObject {
var allEntities = [T]()
// MARK: - Append
func appendEntities(newEntities: [T]) {
....
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想继承它,但是我得到了令人讨厌的错误,我的类型"不符合协议'Equatable'":
看起来斯威夫特的仿制药真的很痛苦.
这是我在日志中看到的内容:
16:33:20.236: Call is Dialing
16:33:21.088: AVAudioSessionInterruptionNotification
16:33:21.450: AVAudioSessionRouteChangeNotification
16:33:21.450: ....change reason CategoryChange
16:33:21.539: AVAudioEngineConfigurationChangeNotification
16:33:21.542: Starting Audio Engine
16:33:23.863: AVAudioSessionRouteChangeNotification
16:33:23.863: ....change reason OldDeviceUnavailable
16:33:23.860 ERROR: [0x100a70000] AVAudioIONodeImpl.mm:317: ___ZN13AVAudioIOUnit11GetHWFormatEjPj_block_invoke: required condition is false: hwFormat
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: hwFormat'
Run Code Online (Sandbox Code Playgroud)
我订阅了两个AVAudioEngineConfigurationChangeNotification
,AVAudioSessionInterruptionNotification
:
@objc private func handleAudioEngineConfigurationChangeNotification(notification: NSNotification) {
println2(notification.name)
makeEngineConnections()
startEngine()
}
@objc private func handleAudioSessionInterruptionNotification(notification: NSNotification) {
println2(notification.name)
if let interruptionType = AVAudioSessionInterruptionType(rawValue: notification.userInfo?[AVAudioSessionInterruptionTypeKey] as! UInt) { …
Run Code Online (Sandbox Code Playgroud) 相反,只出现一个空白视图.
以下是我加载广告请求的方式:
GADMobileAds.configure(withApplicationID: "ca-app-pub-9213331484438711~8534798836") // actual app id
bannerView.delegate = self
bannerView.rootViewController = self
bannerView.adSize = kGADAdSizeLargeBanner
// unit id taken from guide: https://firebase.google.com/docs/admob/ios/quick-start
// Actual unit id doesn't work either.
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
let request = GADRequest()
request.testDevices = [kDFPSimulatorID]
bannerView.layoutIfNeeded()
bannerView.load(request)
Run Code Online (Sandbox Code Playgroud)
我已经开始Allow Arbitrary Loads
了YES
,但这并没有帮助.委托方法甚至不被调用.我错过了什么吗?有没有人能够让Admob在iMessage扩展中工作?
可在此处找到示例项目.
ios ×7
swift ×5
objective-c ×2
sprite-kit ×2
.net ×1
admob ×1
avfoundation ×1
c# ×1
cocoa-touch ×1
generics ×1
imessage ×1
inheritance ×1
ios10 ×1
ios9 ×1
iphone ×1
mkmapview ×1
mvvm ×1
mvvm-light ×1
sktexture ×1
swift2 ×1
uibutton ×1
uicontrol ×1
uiimage ×1
uikit ×1
uitextfield ×1
uitouch ×1
wpf ×1