我注意到,有时将webview移到后台(顶部有另一个视图控制器)时,它会停止JavaScript函数的执行,并仅在返回到前台时才执行它们。
这里有一个类似问题的线程,但是大多数解决方案都是某种黑客行为,例如将Webview添加到键窗口中,或者循环虚拟调用评估JavaScript,这样Webview就不会进入空闲模式并停止JavaScript。
那些解决方案在所有情况下都有效,但是我一点都不喜欢它们。
我想知道是否有更好的解决方案,可以通过任何方法配置webView来防止进入空闲模式,或者采用更优雅的方式对JavaScript进行优先级排序。
谢谢。
有没有办法限制NSAttributedString段落中的行数?
我在NSAttributedString中追加两个字符串,我希望它们最多3行,第一个字符串将是1-2行,如果需要则截断.第二个字符串应该总是在最后一行上
:
this is my first string
if its too long i't will get trun...
But this is my second string
Run Code Online (Sandbox Code Playgroud)
我做的是:
// First string
NSAttributedString *first = [[NSAttributedString alloc] initWithString:@"this is my first string if its too long i't will get trunticated"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:17.0]];
[str appendAttributedString:first];
// New line
[str appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
// Add photo count
NSAttributedString *second = [[NSAttributedString alloc] initWithString:@"But this is my second string"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont …Run Code Online (Sandbox Code Playgroud) contentOffset我想知道使用 CompositionalLayout 设置集合视图的当前方法(如果有)是什么。
我知道 CompositionalLayout 构建不同,并且每个部分都有自己的嵌入式滚动视图,这就是为什么我们必须使用visibleItemsInvalidationHandlergetcontentOffset而不是旧的scrollViewDidScroll(_ scrollView: UIScrollView)委托。但我似乎找不到任何 api 用于设置contentOffset回集合视图(部分或整个组合)。
对于更具体的例子,假设我们有一个集合视图和一个滚动视图,我想在它们之间同步垂直滚动:
收藏视图:
private lazy var collectionView: UICollectionView = {
let collectionViewLayout = createCompositionalLayout()
return UICollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
}()
Run Code Online (Sandbox Code Playgroud)
布局:
private func createCompositionalLayout() -> UICollectionViewLayout {
let layout = UICollectionViewCompositionalLayout { sectionIndex, layoutEnvironment in
let sectionIdentifier = self.dataSource.snapshot().sectionIdentifiers[sectionIndex]
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(self.view.height))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: …Run Code Online (Sandbox Code Playgroud) uikit ios uicollectionview swift uicollectionviewcompositionallayout
我无法在Xcode 6 beta上导入LocalAuthentication.在"使用库链接二进制文件"上添加LocalAuthentication.framework之后,我尝试通过@import LocalAuthentication导入框架/类; 或#import但Xcode无法识别框架.我尝试将设置上的"部署目标"更改为iOS 8.0,但它没有帮助.有任何想法吗?
试图弄清楚如何创建一个以多边形为PrimitiveType的SCNGeometry,我的目标是添加多边形形状的节点作为球面节点的子节点,并使它看起来像MKPolygon的地图工具包,如本例所示。
我当前的代码是:
//Take an arbitrary array of vectors
let vertices: [SCNVector3] = [
SCNVector3Make(-0.1304485, 0.551937, 0.8236193),
SCNVector3Make(0.01393811, 0.601815, 0.7985139),
SCNVector3Make(0.2971005, 0.5591929, 0.7739732),
SCNVector3Make(0.4516893, 0.5150381, 0.7285002),
SCNVector3Make(0.4629132, 0.4383712, 0.7704169),
SCNVector3Make(0.1333823, 0.5224985, 0.8421428),
SCNVector3Make(-0.1684743, 0.4694716, 0.8667254)]
//Does polygon shape require indices?
let indices: [Int] = [0,1,2,3,4,5,6]
let vertexSource = SCNGeometrySource(vertices: vertices)
let indexData = Data(bytes: indices, count: indices.count * MemoryLayout<Int>.size)
//Note!!! I get compiler error if primitiveCount is greater than 0
let element = SCNGeometryElement(data: indexData, primitiveType: .polygon, primitiveCount: 0, …Run Code Online (Sandbox Code Playgroud)