我在我的iOS应用程序中使用自定义动画进行导航.
我有一个子类,UINavigationController其中重写了以下方法:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:transition forKey:@"Push"];
[super pushViewController:viewController animated:NO];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromRight; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:transition forKey:@"Pop"];
UIViewController *poppedVC = …Run Code Online (Sandbox Code Playgroud) 我想将默认行间距增加UITextView10个单位.
这是我的方式:
NSDictionary *attributesDictionary;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 30;
attributesDictionary = @{NSParagraphStyleAttributeName : paragraphStyle , NSFontAttributeName: cellFont};
[str addAttributes:attributesDictionary range:NSMakeRange(0, str.length)];
bodyTextView.attributedText = str;
Run Code Online (Sandbox Code Playgroud)
那么我应该添加10的默认值是什么,并将其设置为linespacing?
我在我的应用程序的导航栏中添加了一个编辑按钮.
我有一个UIViewController,它实现了UITableViewDataSource和UITableViewDelegate.
我使用故事板添加了UITableView,并建立了与数据源和委托的连接.
我在视图控制器的实现文件中这样做了:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[self.editButtonItem setAction:@selector(setEditing:animated:)];
Run Code Online (Sandbox Code Playgroud)
和
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
DLog(@"Editing = %d", editing)
NSLog(editing ? @"Yes" : @"No");
[self.recentSearchList setEditing:editing animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
问题是每当我点击编辑按钮时,BOOL变量"编辑"总是"是".首先,它将UITableView设置为编辑模式,但"编辑"按钮仍然显示"编辑"标签而不是"完成".并且由于参数始终为YES,因此表视图永远不会设置为正常模式.
我从这里的答案中读到:UITableView处于编辑模式 - "编辑"按钮不会改变状态
我假设编辑按钮应该在点击时改变其状态.并且重写方法中的参数也应该切换.
我可以编写自己的代码来在UIViewController中设置标志来检查模式并相应地切换tableView但我假设必须有其他方法.
我有一个NSString可以在字符串之间有多个\n.我需要用单个\n替换\n的多次出现.
我试过这段代码:
newString = [string stringByReplacingOccurrencesOfString:@"\n\n" withString:@"\n"];
Run Code Online (Sandbox Code Playgroud)
但是,如果在字符串中遇到一系列"\n \n \n \n \n \n",则无法获得所需的结果.在这种情况下,它们将被替换为"\n \n \n".
我应该怎么做才能将所有多个"\n"替换为单个"\n"?
谢谢大家!
更新:添加UITextView过滤后的字符串设置为文本的屏幕截图.根据Attila H的回答,在编写代码后,新行似乎不止一行.

我UITableViewCell使用故事板创建了一个自定义.
我正在加载它像这样:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HJAddCell *cell = [tableView dequeueReusableCellWithIdentifier:@"addCell"];
// setting properties of cell
return cell;
}
Run Code Online (Sandbox Code Playgroud)
现在我需要在初始化期间以编程方式添加一些自定义.但问题是在我看来HJAddCell,这些init方法都没有被调用.我应该怎么做才能init调用该方法,或者是否有其他方法可以在初始化时以最少的工作量将更多自定义代码添加到自定义单元类中.
更新:我需要为UILabels添加边框.我在故事板中没有发现任何事情.
我的 iOS 应用程序中有以下代码:
let subAttr: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font : font,
NSAttributedString.Key.foregroundColor : color,
NSAttributedString.Key.writingDirection : NSWritingDirection.leftToRight]
Run Code Online (Sandbox Code Playgroud)
这导致了崩溃:
2019-01-24 18:12:04.425440+0300 Haraj[5461:1355738] -[_SwiftValue count]: unrecognized selector sent to instance 0x281c752f0
2019-01-24 18:12:04.425619+0300 Haraj[5461:1355738] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue count]: unrecognized selector sent to instance 0x281c752f0'
*** First throw call stack:
(0x1f5327ef8 0x1f44f5a40 0x1f523f154 0x1f532d810 0x1f532f4bc 0x1f525b954 0x1f90f5e3c 0x1f90f5cf4 0x1f9049030 0x1f9048fb8 0x1f9003050 0x1f9016e28 0x1f9016b6c 0x1f9004070 0x1ff8d7e2c 0x1ff956e38 0x1ff8dc0b0 0x221be3e24 0x221be446c 0x222536c4c 0x22253740c 0x222537068 0x222541210 0x221be38f0 0x22253fd50 …Run Code Online (Sandbox Code Playgroud) 我需要在我的iOS应用程序中获取全局IP地址.
我搜索但找不到有关获取全球IP地址的任何帖子.他们中的大多数是获取本地IP地址.
我试过这段代码:如何找到iPhone的IP地址.但是这会返回本地IP地址.
对于我的应用程序,我需要获取网站显示的IP地址,例如:
http://myipaddress.com/show-my-ip-address/和 http://whatismyipaddress.com/
是否可以通过编程方式在iOS应用中获取全局IP地址?一种选择是使用上述Web服务,但这些网站的响应将是HTML.是否有任何免费的Web服务可以返回简单的JSON或XML?
快速搜索后,我找不到问题的答案.
这个问题的答案:如何重新格式化自定义UITableViewCell 对我来说不起作用.
当我tableView进入编辑模式时,单元格subViews向右缩进并离开单元格视图.请参阅随附的屏幕截图.
我需要减少压痕,以便它们被移动,但不要超越cell.或者,当它们进入编辑模式时,单元格subViews向左移动一点,以便它们保持在单元格内.
我已经设计了这些UITableViewCell在storyboard.我改变了缩进Level和Width故事板,但它们没有效果.
更新:从NaCl回答后添加了截图
正常模式:

编辑模式:

从NaCl回答后改变

我正在尝试学习适用于 iOS 的 Twilio 视频 sdk。
我实现了以下代码来在视图上显示远程视频。
if let camera = CameraSource(options: options, delegate: self),
let videoTrack = LocalVideoTrack(source: camera) {
let bounds = self.remoteViewHolder.bounds
print("bounds = \(bounds)")
if let renderer = VideoView(frame: self.remoteViewHolder.bounds, delegate: self) {
videoTrack.addRenderer(renderer)
renderer.backgroundColor = .cyan
self.remoteView = renderer
self.localVideoTrack = videoTrack
self.camera = camera
self.remoteViewHolder.addSubview(renderer)
}
}
guard let device = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera, for: .video, position: .front) else {
return
}
self.camera.startCapture(device: device)
Run Code Online (Sandbox Code Playgroud)
问题是视频没有在remoteViewHolderVideoView( ) 的父视图( )renderer上完全显示
我浏览了官方的快速入门指南,但找不到全屏显示视频的方法,即完全覆盖父视图。
请参阅随附的屏幕截图。
如何全屏显示视频?任何帮助,将不胜感激。谢谢你!
ios ×9
objective-c ×7
iphone ×5
uitableview ×3
swift ×2
cocoa-touch ×1
ios7 ×1
nsstring ×1
twilio ×1
uitextview ×1