iPhone:如何在iPhone中显示像控制器与图像的弹出视图?
@devang你一定会明白这一点http://iosdevelopertips.com/open-source/ios-open-source-popover-api-for-iphone-wepopover.html
另一种方法是Mehul建议的。如果您遇到与iPad中的UIPopover相对应的内容,请告诉我们。
尼斯链接。但它只会允许文字而不是图像。我想显示图像。 – Devang 2011-05-22 03:16:36
可以动态采取的UIView,然后在此的UIView添加的UIImageView就这样
UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(XPosition, YPosition, Width, Height)];
UIImage *tmpImg = [UIImage imageNamed:@"YourImageName.png"];
UIImageView *tmpImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, tmpImg.size.width, tmpImg.size.height)];
tmpImgView.image = tmpImg;
[self.view addSubview:tmpView];
希望这会工作....
但它不会像Popoverview在iPad中给出的效果一样。我想在iPhone中有相同的效果! – Devang 2011-05-22 03:06:30
CollectionView可以在屏幕上弹出。下面是完整代码显示的CollectionView的弹出和隐藏弹出窗口
import UIKit
class ViewController: UIViewController , UICollectionViewDataSource, UICollectionViewDelegate {
//let popView = UICollectionView.init(frame: CGRect(x:8,y:30,width:304,height:200))
var demoCollectionView:UICollectionView? = nil;
@IBOutlet var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.loadColorCollectionView()
}
func loadColorCollectionView() {
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10)
layout.itemSize = CGSize(width: 30, height: 30)
demoCollectionView = UICollectionView(frame: CGRect(x:8,y:20,width:304,height:200), collectionViewLayout: layout)
demoCollectionView?.dataSource = self
demoCollectionView?.delegate = self
demoCollectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
demoCollectionView?.backgroundColor = UIColor.white
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1;
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 200;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath);
if indexPath.row%2 == 0 {
cell.backgroundColor = UIColor.red;
}
else{
cell.backgroundColor = UIColor.blue;
}
return cell;
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }
if indexPath.row%2 == 0 {
statusBar.backgroundColor = UIColor.red;
}
else{
statusBar.backgroundColor = UIColor.blue;
}
self.demoCollectionView?.removeFromSuperview()
}
@IBAction func showMessage() {
//popView.backgroundColor = UIColor.darkGray;
//self.view.addSubview(popView)
self.view.addSubview(demoCollectionView!)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//self.popView.removeFromSuperview()
self.demoCollectionView?.removeFromSuperview()
}
}
我在ViewController中创建了一个按钮,并呼吁showMessage按钮()函数,点击它会弹出颜色的CollectionView。在选择颜色弹出将消失。
您以前的问题的可能重复:[如何在iPad中实现模态弹出视图?就像Facebook屏幕使用共享包?](http://stackoverflow.com/questions/5769035/how-to-implement-modal-popup-view-in-ipad-like-facebook-screen-using-sharekit) – 2011-05-21 17:02:08
@Josh:嘿,我要求包括里面的图像与iPhone的弹出效果。不适用于modalpresentview。 – Devang 2011-05-22 03:25:06