1

I have a Navigation Bar, a Search Bar, and below, a Collection View.

My first question : I'd like to have a custom notification bar (alert message ?) that would appear right below my Search Bar, over my Collection View, only the first time I launch my app, with the possibility for the user to close it, like so :

Notification Message/Bar appears over the Collection View

I tried to use UIAlertControllers but obviously it's not gonna make it.

My second question :

Also, how could I manage to get the same Notification Bar/Message, but, this time, instead of placing it over my Collection View, I am trying to find a way to push down my Collection View Cells as my Notification Bar appears (animation?) to create an effect like that :

Collection View pushed down by the Notification Message/Bar

Thank you very much for your help !

Have a nice day,

J.

Vinodh
  • 5,262
  • 4
  • 38
  • 68

2 Answers2

0

You can achieve this by using UICollectionReusableView. You just need to change the height of the header according to your requirement.

here is a sample project i have made for your reference. you can run it and try.

https://mahesh-agrawal@bitbucket.org/mahesh-agrawal/collection-popup-test.git

dropbox link - https://www.dropbox.com/s/j247mfshzld2tuj/collection-popup-test.zip?dl=0

check it.

Mahesh Agrawal
  • 3,348
  • 20
  • 34
  • Hi @M.K. Thanks for your answer ! I could just go through steps 1, 2 and 3, **however I'm not sure how to proceed to change the frame of that view as per runtime requirements, as you suggested.** Concerning the step 4, how can I choose the size (height and width) of my popup programatically without declaring any contraints ? Thanks for your help ! J. –  Nov 02 '16 at 07:13
  • if you want the popup to resize its height according to its inner content, then just add UILabel to the UIView and call layoutIfNeeded for the UIView after giving 4 alignment constraints from the label to the view. And based on the requirement, like i assume there is a close button. on clicking of which you wan this popup to be gone. You can remove the UILabel from the UIView and call layoutIfNeeded with changing the frame height of the UIView to 0. tell me if you need a sample working on your purpose. i will do that and i will give you repo link. but if you got it what i said then its better – Mahesh Agrawal Nov 02 '16 at 10:25
  • sorry, i have tried wrong approach before but i came up with a perfect solution for you. check my edited answer. – Mahesh Agrawal Nov 02 '16 at 11:47
  • Thank you for your detailed answer ! I made some researches about layoutIfNeeded and it looks like a good solution to my problem ! I tried to open the sample project you sent me but I can't open it, could you please send it to me on DropBox or ? Thanks ! –  Nov 03 '16 at 04:10
  • Thank you, I'm checking it out now ! –  Nov 03 '16 at 05:29
0

The first question:
You can add a custom view(your custom notification bar) on top Window .

The second question:
You add custom view above your collectionview, and create outlet for height constraint of this customview.
If have notification, you set heightconstraint # 0 and set = 0 when not (with animation)

Nguyen Hoan
  • 1,583
  • 1
  • 11
  • 18