我使用JSQMesssagesViewController來構建消息傳遞應用程序。我現在可以使用此發送圖像,但想要點擊圖像以全屏方式打開。此功能與標準的消息應用程序類似,可讓您點擊圖像「泡泡」,並捏合放大和縮小。有沒有人有與JSQMessagesViewController這樣做的經驗?感謝那些可以提供幫助的人!從JSQMessagesViewController打開圖片
3
A
回答
10
JSQmessage不處理,但你可以在這個方法中,通過使用zoomPopup類添加此功能:
- (void)collectionView:(JSQMessagesCollectionView *)collectionView didTapMessageBubbleAtIndexPath:(NSIndexPath *)indexPath
{
JSQMessage *message = [self.messageModelData.messages objectAtIndex:indexPath.row];
if (message.isMediaMessage) {
id<JSQMessageMediaData> mediaItem = message.media;
if ([mediaItem isKindOfClass:[JSQPhotoMediaItem class]]) {
NSLog(@"Tapped photo message bubble!");
JSQPhotoMediaItem *photoItem = (JSQPhotoMediaItem *)mediaItem;
[self popupImage:photoItem.image];
}
}
}
- (void) popupImage: (UIImage*)image
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *topView = window.rootViewController.view;
imageView = [[UIImageView alloc] initWithImage:image];
zoomPopup *popup = [[zoomPopup alloc] initWithMainview:topView andStartRect:CGRectMake(topView.frame.size.width/2, topView.frame.size.height/2, 0, 0)];
[popup showPopup:imageView];
}
,你可以在這裏看到zoomPopup: https://github.com/Tintenklecks/zoomPopup
11
SWIFT 3:我發現了另一個無需使用任何其他豆莢/庫。
1)在ChatViewController
的頂部添加var selectedImage: UIImage?
。
2)覆蓋的方法didTapMessageBubbleAt
,例如:
override func collectionView(_ collectionView: JSQMessagesCollectionView!, didTapMessageBubbleAt indexPath: IndexPath!) {
if let test = self.getImage(indexPath: indexPath) {
selectedImage = test
self.performSegue(withIdentifier: "showMedia", sender: self)
}
}
3)添加此功能來獲得時,它的點擊用戶的圖像,並返回一個UIImage
(將返回nil,如果它是一個文本消息已經在錄音):
func getImage(indexPath: IndexPath) -> UIImage? {
let message = self.messages[indexPath.row]
if message.isMediaMessage == true {
let mediaItem = message.media
if mediaItem is JSQPhotoMediaItem {
let photoItem = mediaItem as! JSQPhotoMediaItem
if let test: UIImage = photoItem.image {
let image = test
return image
}
}
}
return nil
}
4)添加SEGUE:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showMedia" {
if let pageDeDestination = segue.destination as? ShowMediaViewController {
pageDeDestination.image = selectedImage!
} else {
print("type destination not ok")
}
} else {
print("segue inexistant")
}
}
5)在界面生成器中,在您的chatVC
附近添加一個視圖控制器,並添加一個segue(類型Show
)和showMedia
作爲segue標識符。在新的viewcontroller
中添加圖像視圖。
6)這裏是我的ShowMediaViewController
代碼:
class ShowMediaViewController: UIViewController {
var image: UIImage? = nil
var titreText: String!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var titre: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
//titre.text = titreText
if image != nil {
imageView.image = image
} else {
print("image not found")
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
不要忘了把「看點合格」作爲參數在圖像示意圖(在界面生成器),以正確地顯示圖像。
0
如果與PhotoSlider(https://github.com/nakajijapan/PhotoSlider)
// var images = [UIImage]() // puts images of messages here
override func collectionView(_ collectionView: JSQMessagesCollectionView!, didTapMessageBubbleAt indexPath: IndexPath!) {
let index = indexPath.row
let message = messages[index]
if message.isMediaMessage {
if message.media.isKind(of: JSQPhotoMediaItem.self) {
let photoSlider = PhotoSlider.ViewController(images: images)
let i = images.index(of: (message.media as! JSQPhotoMediaItem).image)!
photoSlider.currentPage = i
photoSlider.modalPresentationStyle = .overCurrentContext
photoSlider.modalTransitionStyle = .crossDissolve
present(photoSlider, animated: true, completion: nil)
}
}
}
相關問題
- 1. 從IsolatedStoreage打開圖片?
- 2. 從圖庫中打開圖片
- 3. 使用打開方式在圖片框中打開圖片
- 4. 打開圖片元標記
- 5. 時jpg圖片打開
- 6. 打開圖片庫Android
- 7. PictureBox打開圖片 - C#
- 8. 從cardView打開片段
- 9. 從RecyclerViewAdapter打開片段
- 10. 從另一個片段打開片段
- 11. 從片段錯誤中打開片段
- 12. 圖片地圖新視圖打開
- 13. 如何選擇照片並從片段中打開圖庫?
- 14. Android意圖打開圖片庫,但不是圖片。爲什麼?
- 15. 從圖庫中選擇圖片android原始圖像未從外部打開
- 16. Android SQLite打開圖片URI,但無法打開內容:
- 17. JSQMessagesViewController消息視圖錯誤
- 18. JSQMessagesViewController用戶添加圖像
- 19. 圖片點擊打開圖片專輯的燈箱
- 20. 打開xml SDK。插入圖片時無法顯示圖片
- 21. 打開一個圖片點擊另一個圖片等等
- 22. 圖片庫不在鈦打開1.0
- 23. Android無法打開意圖的照片
- 24. 用css和圖片打開新窗口
- 25. 使用PIL打開POST文件圖片
- 26. FileNotFound當在Android中打開圖片時
- 27. 嵌入總結在打開圖片
- 28. 如何在打開時切換圖片
- 29. 用Ionic/angularjs打開圖片庫
- 30. 用jQuery點擊打開圖片庫
我對JSQMessageView控制器工作使用。請看看這個問題http://stackoverflow.com/q/38371995/2522603 – ChenSmile