在Safari中,如果你使用的3D觸摸,即觸摸的鏈接與sourceRect有圓角。當我設置在源rect:func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
上previewingContext,我只能設置previewingContext.sourceRect
這並不讓我圓邊角,或者設置多角球區。我怎樣才能做到這一點?我怎樣才能將sourceRect的角落變成Peek和Pop 3D Touch?
4
A
回答
6
可以間接地通過增加一個圓角半徑爲sourceView的層設置圓角與sourceRect。當您將previewingContext.sourceRect
設置爲sourceView的邊界時,保持焦點的區域也將具有圓角。
下面是一個使用可按壓的UILabel一個例子:
class ViewController: UIViewController {
var previewingContext: UIViewControllerPreviewing?
let label = UILabel(frame: CGRectMake(150, 250, 100, 50))
override func viewDidLoad() {
super.viewDidLoad()
let background = UIImageView(frame: view.bounds)
background.image = UIImage(named: "image.jpg")
view.addSubview(background)
label.backgroundColor = UIColor.whiteColor()
label.text = "Press me!"
label.textAlignment = .Center
label.layer.cornerRadius = 20
label.clipsToBounds = true
label.userInteractionEnabled = true
view.addSubview(label)
previewingContext = registerForPreviewingWithDelegate(self, sourceView: label)
}
}
extension ViewController: UIViewControllerPreviewingDelegate {
func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
previewingContext.sourceRect = label.bounds
return UIViewController()
}
func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
showViewController(viewControllerToCommit, sender: self)
}
}
-2
首先在sourceView應該有一個cornerRadius的層上,確實模糊效果將有一個圓角半徑只有sourceView的圖層有一個。由於sourceView是隻讀的,因此在使用方法registerForPreviewingWithDelegate:sourceView:
進行註冊時應該設置它。
如結合其細胞角半徑的集合視圖爲例,登記可以在collectionView:cellForItemAtIndexPath:
製成。而對於安全性,並作爲previewingContext將在稍後檢查,我保持一個弱指針previewingContext在細胞本身返回由registerForPreviewingWithDelegate:sourceView:
:
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
id previewingContext = [self registerForPreviewingWithDelegate:self sourceView:cell];
cell.weakPreviewingContext = previewingContext;
}
的方法然後UICollectionViewDelegate協議collectionView:didEndDisplayingCell:forItemAtIndexPath:
我做的註銷這樣的:
if (collectionView == self.collectionView) {
if ([cell isKindOfClass:UserInHomeCollectionCell.class]) {
[self unregisterForPreviewingWithContext:((UserInHomeCollectionCell*)cell).weakPreviewingContext];
}
}
最後在UIViewControllerPreviewingDelegate協議的previewingContext:viewControllerForLocation:
我提出的安全檢查等,該方法:
UserInHomeCollectionCell *cell = (UserInHomeCollectionCell*)[(UIViewController*)previewingContext view];
NSAssert([cell isKindOfClass:UserInHomeCollectionCell.class], @"***** INTERNAL ERROR: Invalid class for retrieved cell %@", cell);
NSAssert([previewingContext isEqual:((UserInHomeCollectionCell*)cell).weakPreviewingContext], @"***** INTERNAL ERROR: Invalid Previewing Context");
相關問題
- 1. 3D Peek&Pop搜索結果
- 2. 3D Peek和Pop內存泄漏
- 3. 3D Touch從UITableViewCell觸摸Peek和Pop如何將數據交給其他UIViewController?
- 4. 我怎樣才能圍繞QWidgets的角落?
- 5. 我怎樣才能把它變成shellcode?
- 6. 我怎樣才能繞過這兩個角落?
- 7. 我怎樣才能在角服務
- 8. 我怎樣才能在角2
- 9. 我們怎樣才能在角
- 10. 我怎樣才能
- 11. 我怎樣才能
- 12. 我怎樣才能
- 13. 我怎樣才能
- 14. 我們怎樣才能生成rspec的
- 15. 我怎樣才能讓我的圈子變成白色?
- 16. Peek和Pop函數SpriteKit
- 17. 我怎樣才能完全控制我的3D人體模型?
- 18. 我怎樣才能生成一個PDF
- 19. 我怎樣才能成爲一個index.jade?
- 20. 我怎樣才能生成@Enumerated與hibernate.reveng
- 21. 我怎樣才能將我的db分成1mb的塊?
- 22. 我怎樣才能使零刻度出現在R圖的左側角落?
- 23. 我怎樣才能的MSBuild
- 24. 我怎樣才能在角模式使用timepicker形成
- 25. 我怎樣才能加密MD5變量?
- 26. 我怎樣才能ORDER BY變量?
- 27. 我怎樣才能改變數獨
- 28. 我怎樣才能改變這與jquery?
- 29. 我怎樣才能改變IE
- 30. 我怎樣才能改變/在商店
嗨@joem,怎麼會去實現這個了'UITableView',在這個意義上,我大概不應該讓一個'ID'每一個'UITableViewCell',但想顯示一些圓角的意見,(例如。像Apple在消息應用程序中所做的那樣; 3D觸摸頭像) –
brechtb