Home  >  Article  >  Backend Development  >  iOS development questions (11)

iOS development questions (11)

黄舟
黄舟Original
2017-01-20 09:54:111309browse

131. How to restrict ScrollView from scrolling in a certain direction?
For example, to restrict scrolling in the x direction, you can implement the UIScrollViewDelegate protocol method:

func scrollViewDidScroll(scrollView: UIScrollView) {
ifabs(scrollView.contentOffset.x) > 0 {
scrollView.contentOffset= CGPointMake(0, scrollView.contentOffset.y)
}
}

132. How to import the O-C framework into the Swift Framework target
Take BmobSDK as an example (CommonCrypto, etc. C/O-C framework is the same), when you add BmobSDK to Link Binary With Libraries, when you use the "importBmobSDK" statement, an error occurs: no such module
If you try to import BmobSDK using bridging headers, then will cause another error.
This is because Swift Framework does not support bridging headers files.
To solve this problem, you need to go through the following steps:
1) Create the BmobSDK directory in the project directory and place BmobSDK.framework in this directory. At the same time, create a module.map file in this directory with the following content:

module BmobSDK [system] {
header"/Users/kmyhy/Documents/Swift/code/第12章/kNote/BmobSDK/BmobSDK.framework/Headers/Bmob.h"
link "BmobSDK"
export *
}

This will allow us to use BmobSDK as a Swift module.
2) In Build Settings, find Import Paths (SWIFT_INCLUDE_PATHS) and add the BmobSDK directory. As shown in the figure below:

3) Import the BmobSDK framework in the swift file:
import BmobSDK

133. How to use CocoaPods in App Extension
Add this sentence in the Podfile :
link_with 'Extended name'
Add the bridging header file and set the Objective-C BridgingHeader.
134, error 'xxx.pch' has been modified since the precompiled header was builterror in Xcode
Execute deep Clean (shortcut key Option+Command+Shift+K)

135, Document Provider extension , the documentStorageURL property of DocumentPickerViewController returns nil.
Confirm that the App Groups of the container App, Document Provider extension and File Provider extension are set correctly. If there are any exclamation marks, please Fix them.
136. Inserting and deleting Cells in CollectionView
Same as TableView, we can use insertItemsAtIndexPaths()/deleteItemsAtIndexPaths() to insert/delete cells. The difference is that CollectionView no longer supports the beginUpdates()/endUpdates() operations. Insertion/deletion animation is supported by default. If you do not want the default animation effect, you can set the animationsEnabled property of UIView:

BOOL animationsEnabled = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[myCollectionView reloadItemsAtIndexPaths:myIndexPaths];
[UIView setAnimationsEnabled:animationsEnabled];

137. UICollectionView in UIScrollView will not scroll
Check whether UIScrollView is set delegate property, and check whether the scrollViewDidScroll method is implemented in delegate. If so, please delete the method (just canceling the delegate attribute will not work).
Also check the width (or width constraint), height (or height constraint), and list content size of UICollectionView, because when the list content is smaller than the width (or height) of UICollectionView, the scroll bar in this direction will not appear.
138. Why does the cell display incorrectly when it uses UITableViewCellStyleValue1?
UITableViewCell has several built-in types, such as UITableViewCellStyleDefault, UITableViewCellStyleValue1, and UITableViewCellStyleValue2.
These Cells are pre-configured by the SDK, and they present fixed built-in styles, such as font size, color, alignment, etc. If you want to modify these configurations, it is likely that the display is abnormal. For example, some text can be displayed for a while, and then not displayed, or the inherent font (and color) is displayed for a while, and then (for example, clicking a cell) is displayed again. Display the modified font (and color).
In this case, you're better off customizing your own cell (subclassing).
139. The size calculated by boundingRectWithSize is incorrect?
Pay attention to providing the correct options parameters. For UILabel, you need to use at least two options: UsesLineFragmentOrigin and UsesFontLeading:

CGRect paragraphRect =
[attributedTextboundingRectWithSize:CGSizeMake(300.f, CGFLOAT_MAX)
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
context:nil];

140. Bitwise OR (|) operation cannot be performed on multiple enumeration values ​​in Swift
Note that this problem is Fixed in iOS 8.3 SDK Beta 1 (12F5027d). For SDKs lower than this version, we can use the following code instead:

let options =unsafeBitCast(NSStringDrawingOptions.UsesLineFragmentOrigin.rawValue |
NSStringDrawingOptions.UsesFontLeading.rawValue,
NSStringDrawingOptions.self)
let frame = text.boundingRectWithSize(size, options:options, attributes:D,context:nil)

The above is the content of iOS Development Questions (11). For more related content, please pay attention to the PHP Chinese website (www.php .cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn