As seen in screenshot, I have two stationary green and red views side by side.
Blue view is dragable.
What I want is, when the blue view is dragged between green and red view, to move red and green views and make space for the blue view to be dropped. If blue view is dropped elsewhere, it is to return to its original position.
I am able to drag the blue view, but not sure how to "Detect when the blue view is in between green and red and then drop it in place". Help in swift will be highly appreciated.
I was able to solve this (thanks to #rdelmar pointer).
1) Use 'CGRectIntersectsRec' to test when blue view is intersecting with both red and green.
2) Move red to right and green to left by half their width.
3) Copy blue view's size to create an invisible new view and place it between red and green.
4) test for when blue view is NOT intersecting with new invisible view, then remove the invisible view and move back red and green.
Related
I am trying to create an animation where an image view is moving up and down vertically. I have a line that the imageview is passing through, and my intention is to have the imageview hide partially when passing through the line. For example, if the line is halfway between the imageview, then the bottom half of the imageview should be hidden. Therefore, it would be ideal if there was a library of function that could hide a fraction of the imageview based on a specified y position. Please find examples of what I mean in the attached screenshots.
In this screenshot, the part of the circle (imageview) underneath the line should be hidden, but the top half should be shown.
Also, keep in mind that the background is a changing gradient so I wouldn't be able to use a rectangular view with the same background color to hide the circle.
This question already has answers here:
drawRect over subviews?
(3 answers)
Closed 8 years ago.
I have a UIView that I've designed in xib:
You can see that it consists of three things: Two large views on either side which are just empty for now, and then a gray bar in the middle (which is itself a UIView).
In some conditions, I want to draw horizontal blue lines on top of the entire page. But what's happening is that because of the views on the left and right, the horizontal blue lines are only showing in the middle. How can I draw ON TOP of the views that exist within my view? In other words, how do I get those blue lines to show up on the whole screen (the drawing commands have them being drawn much longer than they show up as). Stated another way, I need to set the Z dimension of my blue lines to be on top of everything else.
I would have this sort of view hierarchy:
Main view has 3 subviews: left, right, center. Center is in front of left and right, and is sized so that it fits the width of the blue bars.
Center has a subview that is the vertical line, and a subview that contains the blue lines, and is made to have a transparent background. The vertical line view should have Z dimension higher than the one containing the blue lines.
When you draw the center, you can set the blue lines subview to be visible/invisible as needed.
I have a pretty simple scroll view (code below) which i have a picture on
self.detailViewController.scroll.contentSize=CGSizeMake(320, 1200);
self.detailViewController.scroll.showsHorizontalScrollIndicator=YES;
However when i "Scroll to the extreme button or extreme top of the picture or extreme button of the "scroll view, it loops and shows the top of the picture or loops back to the buttom of the picture.
I was wondering if there was some sort of "no repeat" i could set so it shows "black" instead of back to the top of the picture.
Thank you.
colorWithPatternImage tiles the image that it is given. So setting it as the background colour will always result in 'wrap around' if the scroll view can be scrolled outside the edges of the tile image.
To prevent this, choose one of:
Set the content size to the size of the tile image and turn off bouncing
Don't use colorWithPatternImage, use a UIImageView added as a subview of the scroll view.
I'm using UICollectionView with different sections, the problem is within a section if there are not enough item, the only items are centred, is there a way to make it layout cells to be from left to right and top to bottom? Without adding transparent placeholder cells?
Thanks
edit:
Screen shot added, so section 1 has the big orange bar and two small green bars, the one on the right of big orange bar should be in section 1, so I want it to be below the big orange bar, next to another green bar which is already there.
Also, say if section 1 has only 1 big orange bar, I want it to be top aligned, but it is centered.
I have a few moving views which are semi-transparent, at some point they will be overlapping. Is it possible to make the overlapped part "invisible" through the top most view?
For example, 3 UIViews a background (which is stationary) and 2 subviews (the semi-transparent ones) and when they overlap the lower subview will be "invisible" under the top subview, all the while i can still see the background view and the part of the lower subview which isn't overlapping the other view.
Here's an image to help clarify the before and after they overlap.
Before Overlap:
After Overlap:
(the view on the far right looks a little strange because it blends with the white background)