简体   繁体   中英

UIView center X UIImageView

In one UIVIew i have 5 icon (UIImageView). I show/hide icons. Its ok. But i want if i hide 2 icon the rest what not hidden (or not removed) show center of the View.

if show all:

http://sherad.info/elotte.jpg

I remove from view 2 icon (i try the set hiden but the effect same)

[share removeFromSuperview]; [sms removeFromSuperview];

After this:

http://sherad.info/utana.jpg

I want the 3 icon show in center of view. So somehow re arrange the icons inside the UIView. How i can solved this? thx.

I'll assume the black area behind the icons is a UIView and the icons have been added to it in a static position? What if, instead, you created a second UIView that was transparent. Determine what icons you want to display and add them into the second view. It would start off with the second view being the exact same size as the first view, but once you want to display less, remove all the icons from the second view

for (yourIcon *icon in [secondView subviews]) {
    [icon removeFromSuperview];
}

reset the frame of the second view to be the length you want and re-add the icons, then place it in the center of the first view

secondView.center = firstView.center;

and either do

[secondView setNeedsDisplay]

or re-add it as a subview of firstView if you previously removed it (which I don't believe is necessary).

The subviews should position themselves relative to each other based on how many other icons there are. Every time there is an event that add or removes an icon you should call some layout code that will make the icons postion themselves.

Removing a view should have the superview count the added subviews, create new x coordinates based on the screen width divided by the count and then set the frames of all of the subviews.

There is probably a way to do this with autolayout but I'm not familiar with those methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM