为了管理内容可编辑UIWebView中的自动滚动,我需要获得正确的插入符Y垂直坐标.
我使用javascript确定了两种方法.
第一个使用getClientRects javascript函数:
CGRect caretRect = [self.webView stringByEvaluatingJavaScriptFromString: @"
var sel = document.getSelection();
var range = sel.getRangeAt(0).cloneRange();
range.collapse(true);
var r =range.getClientRects()[0];
return '{{'+r.left+','+r.top+'},{'+r.width+','+r.height+'}}';"];
int caretY = caretRect.origin.y;
Run Code Online (Sandbox Code Playgroud)
这样,插入符号一直闪烁,一个问题得到正确的垂直位置,有一个问题:当用户键入返回键时,下一行为空,在键入字符键之前,caretY等于零.这样的方法就无法使用了.
第二个插入一个tmp span,然后将其删除:
int caretY = [[self.webView stringByEvaluatingJavaScriptFromString: @"
var sel = window.getSelection();
sel.collapseToStart();
var range = sel.getRangeAt(0);
var span = document.createElement(\"span\");
range.insertNode(span);
var topPosition = span.offsetTop;
span.parentNode.removeChild(span);
topPosition;"] intValue];
Run Code Online (Sandbox Code Playgroud)
这在任何情况下都给出了正确的照顾.但插入符号停止闪烁,这在屏幕上看起来非常无益.
有没有人知道可以做出以下的任何方法(或这些方法的改编):
- get the correct caret Y in any situation
- keep the caret blinking in any situation
Run Code Online (Sandbox Code Playgroud)
谢谢
我的iPad声音应用程序(iOS 7.1)能够在后台录制.只要录制在后台不中断,一切都可以.例如,如果一个人有(愚蠢的?)想法在录制内容时开始听音乐.
我试图以不同的方式管理这种中断,但没有成功.问题是,
- (void)audioRecorderEndInterruption:(AVAudioPlayer *)p withOptions:(NSUInteger)flags
Run Code Online (Sandbox Code Playgroud)
当应用程序在后台发生中断时,永远不会被触发.然后我尝试在另一个解决方案中实现AVAudioSessionInterruptionNotification和handleInterruption:方法as
- (void) viewDidAppear:(BOOL)animated
{
......
AVAudioSession *session=[AVAudioSession sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleInterruption:)
name:AVAudioSessionInterruptionNotification
object:session];
.......
}
// interruption handling
- (void)handleInterruption:(NSNotification *)notification
{
try {
UInt8 theInterruptionType = [[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] intValue];
NSLog(@"Session interrupted > --- %s ---\n", theInterruptionType == AVAudioSessionInterruptionTypeBegan ? "Begin Interruption" : "End Interruption");
.... MANAGE interruption begin
interruptionBeganWhileInBackgroundMode = TRUE;
}
if (theInterruptionType == AVAudioSessionInterruptionTypeEnded) {
.... MANAGE interruption end
}
} catch (CAXException e) {
char buf[256];
fprintf(stderr, …Run Code Online (Sandbox Code Playgroud) 我根据Apple的SpeakHere音频应用示例编写了一个小型录音机/播放器,可以在我的iPad上使用.当用户要求显示录像机时,UIView将打开并显示录制/停止按钮和仪表.
当我从头开始加载应用程序时,我可以记录,停止记录,再次记录我想要的任何时间.停止录制后,我将应用程序放在后台,例如阅读我的邮件.再次将录音机置于前台时,无法录制任何声音.我在日志中收到错误消息,仪表不显示任何数据,也没有创建声音文件.我注意到与iPhone和iPad上的SpeakHere示例应用程序相同的行为.唯一的解决方案是退出并重新启动应用程序.
为了解决这个问题,我决定在用户完成录像机的使用后取消分配视图控制器.我为记录视图控制器禁用了ARC,并编写了dealloc方法.在这个控制器的viewDidDisappear中,我进行了[self dealloc]调用.
但程序崩溃,发送[RecorderViewController childViewControllersCount]:消息发送到解除分配的实例.我想这样的自我dealloc是不允许的......
我需要找到一个解决方案,或者......
找到一种在应用程序进入后台时正确管理音频会话的方法(因为录制停止,我不明白为什么会出现这样的问题).
或者在视图关闭时正确释放录像机视图控制器,以确保在视图必须出现的任何时候,它都会从控制器的XIB文件中再次加载.
[更新]在查看aurioTouch应用程序的代码(Apple dev网站的另一个音频示例)后,我在我的应用程序委托中获得了以下代码:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
AudioSessionSetActive(true);
}
Run Code Online (Sandbox Code Playgroud)
它可以在我的应用程序或SpeakHere应用程序中运行...花了很多时间找到一个解决方法,这是一行代码!
iOS 6 已更新为使用 UITextView 进行富文本编辑(UITextView 现在获得属性文本属性 \xe2\x80\x94,该属性是愚蠢的不可变\xe2\x80\x94)。这是在 NDA 下在 iOS 6 Apple 论坛上提出的问题,由于 iOS 6 现已公开,因此可以公开该问题......
\n\n在 UITextView 中,我可以撤消任何字体更改,但无法撤消视图属性字符串副本中的替换。使用此代码时...
\n\n- (void) replace: (NSAttributedString*) old with: (NSAttributedString*) new\n\n{\n1. [[myView.undoManager prepareWithInvocationTarget:self] replace:new with:old];\n2. old=new;\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n...撤消效果很好。
\n\n但是,如果我添加一行以使结果在我的视图中可见,则 undoManager 不会触发“replace:with:”方法,因为它应该......
\n\n- (void) replace: (NSAttributedString*) old with: (NSAttributedString*) new\n\n{\n1. [[myView.undoManager prepareWithInvocationTarget:self] replace:new with:old];\n2. old=new;\n3. myView.attributedText=[[NSAttributedString alloc] initWithAttributedString:old];\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n任何想法?我对任何替换方法都有同样的问题,无论是否使用范围,对于我尝试在“2”行使用的 MutableAttributedString...
\n在一个令人满意的UIWebView中,当我复制然后粘贴一些文本时,内容会粘贴它可能具有的任何粗体或斜体属性,但是字体总是被Times(总是带有size ="3")替换,无论它在复制中是什么文本(例如Helvetica).几周前我在Apple的bug网站上提交了一个雷达,但没有得到消息.有任何想法可以解决方法吗?
我有一个 ViewController,它在 AddressBook 中获取数据。为了在获取数据时收到通知,我向此 ViewController 发布通知以允许它更新 NSViewTable(在主队列中)。当用户结束在 ViewController 视图中编辑 NSTextField 时,此 ViewController 会显示一个瞬态 NSPopover .
当我在此字段中输入第一个字符串时,弹出窗口将显示,然后在用户完成与其交互时关闭。如果我再次编辑文本字段,Popover 不会出现在视图中,但提取过程开始。当它结束并且DataUpdated专门用于通知帖子的方法被触发时。然后我dispatch_sync(dispatch_get_main_queue(), ^{在线路上崩溃了(控制台中没有消息,即使启用了 NSZombie)。这是弹出内容 ViewController 中的代码:
- (void) getContactForName: (NSString *) name
{
CNEntityType entityType = CNEntityTypeContacts;
if ([CNContactStore authorizationStatusForEntityType:entityType]){
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:entityType completionHandler:^(BOOL granted, NSError * _nullableError){
if (granted) {
if ([CNContactStore class]){
NSError *contactError;
CNContactStore *addressBook = [[CNContactStore alloc] init];
[addressBook containersMatchingPredicate:[CNContainer predicateForContainersWithIdentifiers:@[addressBook.defaultContainerIdentifier]] error:&contactError];
NSArray * keysToFetch =@[CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactFamilyNameKey, CNContactGivenNameKey, CNContactIdentifierKey];
NSError *error; …Run Code Online (Sandbox Code Playgroud) 我尝试使用内容可编辑的UIWebView创建一个富文本编辑器,因为UITextView没有得到任何丰富.我想知道如何以编程方式替换选择或插入HTML代码(例如,创建指向所选文本的链接,或实现搜索/替换功能).我试过了:
[self.webTexteView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.ExecCommand('insertHTML', false, '%@')", myString]];
Run Code Online (Sandbox Code Playgroud)
但它不起作用......你知道是否有解决方案吗?
谢谢,
丹尼斯
ios ×5
uiwebview ×3
background ×1
caret ×1
coordinates ×1
html ×1
interrupt ×1
ios6 ×1
javascript ×1
macos ×1
uipasteboard ×1
uitextview ×1