iPhone: Как отобразить всплывающее окно в виде контроллера с изображением в iPhone? - PullRequest
7 голосов
/ 21 мая 2011

Я хочу отобразить небольшое всплывающее окно (так же, как всплывающее окно в iPad, но здесь я хочу в iPhone) в iPhone с изображением.

Как я могу это сделать?

Ответы [ 3 ]

5 голосов
/ 21 мая 2011

@ devang вы наверняка оцените это http://iosdevelopertips.com/open-source/ios-open-source-popover-api-for-iphone-wepopover.html

Другой подход - это то, что предложил Мехул. Дайте нам знать, если вы встретите что-то, что соответствует UIPopover в iPad.

4 голосов
/ 21 мая 2011

Вы можете динамически использовать UIView, а затем добавить UIImageView в этот UIView точно так же, как это

    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];

Надеюсь, это сработает ....

0 голосов
/ 03 июля 2017

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 () при нажатии кнопки, чтобы открыть представление коллекции с цветами. При выборе цвета всплывающее окно исчезнет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...