I want help with my UIScrollView:
I have implemented my UIScrollView in my project and everything works fine but I have problems when Im trying to implement zoom, but this is not as the zoom when we are looking a picture. I am trying to zoom out. My app begins as this graphic when it launches. Lets suppose that I have a UIView in the screen which is bigger than my screen.
--------------------------------------------
| | | |
| | | |
| -----|----------------------|---------|
| | | | |<---------UIView
| | | |<------------------ iPhone Screen frame
| | | | |
| -----|----------------------|---------|
| | | |
| | | |<-------- ScrollView Content size
| | | |
| | | |
| | |<----------------- ScrollView Frame Size
| | | |
| | | |
| | | |
| | | |
| | | |
| ------------------------ |
| |
| |
| |
--------------------------------------------
And I want my screen look like this when I zoom out.
------------------------
| |
| ------------------|
UIView-------->| |
| | |
| ------------------|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
------------------------
How can I do it?
Set scrollView.minimumZoomScale = 0 then you can zoom out as much as you want. If you don't want to zoom out too much, give it a reasonable value.
Related
If I in Google Sheets have a series defined as
[29060, 29062, 29331, 29332, 29333, 29334, 29335, 29336, 29337, 29338, 29339, 29340, 29341,
29342, 29372, 29373].
How do I make them line up in intervals like this?
|To |From |
|29060 |29062 |
|29331 |29342 |
|29372 |29373 |
I can't find any good answers for this anywhere. Please, help!
Data/Formulas
A1:
29060, 29062, 29331, 29332, 29333, 29334, 29335, 29336, 29337, 29338, 29339, 29340, 29341,
29342, 29372, 29373
B1: =transpose(split(A1,",")). Converts the input text is an a vertical array.
C1: =FILTER(B1:B16,mod(ROW(B1:B16),2)<>0). Returns values in odd rows.
D1: =FILTER(B1:B16,mod(ROW(B1:B16),2)=0). Returns values in even rows.
E1: =ArrayFormula(FILTER(C1:C8,{TRUE();C2:C8<>D1:D7+1})). Returns values that start a range.
F1: =ArrayFormula(FILTER(D1:D8,{D1:D7+2<>D2:D8;TRUE()})). Returns values that end a range.
Result
Note: A1 values are not shown for readability.
+----+---+-------+-------+-------+-------+-------+
| | A | B | C | D | E | F |
+----+---+-------+-------+-------+-------+-------+
| 1 | | 29060 | 29060 | 29062 | 29060 | 29062 |
| 2 | | 29062 | 29331 | 29332 | 29331 | 29342 |
| 3 | | 29331 | 29333 | 29334 | 29372 | 29373 |
| 4 | | 29332 | 29335 | 29336 | | |
| 5 | | 29333 | 29337 | 29338 | | |
| 6 | | 29334 | 29339 | 29340 | | |
| 7 | | 29335 | 29341 | 29342 | | |
| 8 | | 29336 | 29372 | 29373 | | |
| 9 | | 29337 | | | | |
| 10 | | 29338 | | | | |
| 11 | | 29339 | | | | |
| 12 | | 29340 | | | | |
| 13 | | 29341 | | | | |
| 14 | | 29342 | | | | |
| 15 | | 29372 | | | | |
| 16 | | 29373 | | | | |
+----+---+-------+-------+-------+-------+-------+
I am trying to achieve a layout of buttons very similar to Apple's inbuilt Calculator app:
I am using autolayout to position the buttons, and drawing a 0.5px border on each button, aiming for a 1px gap between buttons (like the calc app, closeup showing pixels above, from a retina device).
Border applied by :
btn.layer.borderWidth=0.5f;
btn.layer.borderColor=[[UIColor blackColor] CGColor];
and the layout is set up using Interface Builder.
It almost works; but there is some variability in the gap between buttons - for example the gap between the "1,2,3,thru" row and the "4,5,6,and" row is 2 pixels, but the gap between the "7,8,9" and "cl,0,#" rows is only one pixel.
Constraints are :
Top black area has a fixed height
All buttons same height
In the numeric rows, numeric buttons are set to same width, THRU, AND, ALL OFF and ENTER buttons are set to same fixed width
Top row of buttons pinned to bottom of black area, bottom row pinned to bottom of superview
In IB the buttons are all positioned butting up against each other.
In interface builder and at runtime I don't see any autolayout errors; and a debugger dump of the autolayout info gives me:
po [[UIWindow keyWindow] _autolayoutTrace]
*<UIWindow:0x10908a560> - AMBIGUOUS LAYOUT
| *<UILayoutContainerView:0x109136140>
| | *<UINavigationTransitionView:0x10908ef80>
| | | *<UIViewControllerWrapperView:0x109138870>
| | | | *<UIView:0x1090e6d10>
| | | | | *<UILabel:0x1090d5bb0>
| | | | | *<UIButton:0x1090d27e0>
| | | | | | <UIButtonLabel:0x1091c9190>
| | | | | *<UIButton:0x1090844c0>
| | | | | | <UIButtonLabel:0x1091c7990>
| | | | | *<UIButton:0x109088b60>
| | | | | | <UIButtonLabel:0x1091c6190>
| | | | | *<UIButton:0x1090e2ce0>
| | | | | | <UIButtonLabel:0x1091c4990>
| | | | | *<UIButton:0x1090e4e50>
| | | | | | <UIButtonLabel:0x1091c3190>
| | | | | *<UIButton:0x1090db730>
| | | | | | <UIButtonLabel:0x1091c1990>
| | | | | *<UIButton:0x109068f50>
| | | | | | <UIButtonLabel:0x1091c0190>
| | | | | *<UIButton:0x10906db80>
| | | | | | <UIButtonLabel:0x1091be990>
| | | | | *<UIButton:0x1090d23a0>
| | | | | | <UIButtonLabel:0x1091bd190>
| | | | | *<UIButton:0x1090c8520>
| | | | | | <UIButtonLabel:0x1091bb990>
| | | | | *<UIButton:0x1090c9090>
| | | | | | <UIButtonLabel:0x1091ba190>
| | | | | *<UIButton:0x1090c5680>
| | | | | | <UIButtonLabel:0x1091b8990>
| | | | | *<UIButton:0x1090d7fa0>
| | | | | | <UIButtonLabel:0x1091b7190>
| | | | | *<UIButton:0x1090cc820>
| | | | | | <UIButtonLabel:0x1091b5990>
| | | | | *<UIButton:0x10909dda0>
| | | | | | <UIButtonLabel:0x1091b4190>
| | | | | *<UIButton:0x1090c8090>
| | | | | | <UIButtonLabel:0x1091b2990>
| | | | | *<UIButton:0x1090c8e30>
| | | | | | <UIButtonLabel:0x1091b1190>
| | | | | *<UIButton:0x1090d5390>
| | | | | | <UIButtonLabel:0x1091af990>
| | | | | *<UIButton:0x10d30d260>
| | | | | | <UIButtonLabel:0x1091ae190>
| | | | | *<UIButton:0x10909a6a0>
| | | | | | <UIButtonLabel:0x1091ac990>
| | | | | *<UIButton:0x1090cca40>
| | | | | | <UIButtonLabel:0x109161160>
| | | | | *<UIButton:0x10d30ea90>
| | | | | | <UIButtonLabel:0x109156460>
| | | | | *<UIButton:0x1090da9e0>
| | | | | | <UIButtonLabel:0x109177ad0>
| | | | | *<_UILayoutGuide:0x1090e6dd0> - AMBIGUOUS LAYOUT
| | | | | *<_UILayoutGuide:0x1090ce080> - AMBIGUOUS LAYOUT
| | <UINavigationBar:0x10907da60>
| | | <_UINavigationBarBackground:0x109087240>
| | | | <_UIBackdropView:0x1090899f0>
| | | | | <_UIBackdropEffectView:0x10908b110>
| | | | | <UIView:0x10908bbb0>
| | | | <UIImageView:0x1090877a0>
| | | <UINavigationItemView:0x10916bc30>
| | | | <UILabel:0x10917f810>
| | | <UINavigationItemButtonView:0x1090ee060>
| | | | <UILabel:0x1090ee5d0>
| | | <_UINavigationBarBackIndicatorView:0x109098c80>
Can anyone offer any hints on how to achieve a "pixel perfect" layout like this with Autolayout? Or should I be doing this programatically instead?
Layer borders are drawn inside the views bounds, so you aren't going to see a "gap" between the buttons, but the effect of two borders abutting each other. This isn't going to work in the non-retina simulator or devices, since it can't draw a half-pixel, and Autolayout doesn't align views on half-pixels.
For a layout like the one above I'd be giving a fixed height to the buttons (or to one button, and making the others equal it) and letting the black view take up the remaining space. It's always best to have at least one (ideally, exactly one) variable element in a full-screen layout basically to cover rounding errors.
It sounds at the moment like you have one fixed element (the black view) and the buttons are basically "take the remaining height and divide it between yourselves", which will only work if the remaining height divides perfectly.
I tried to set horizontal/vertical spaces between views equal to 0.5. The color of parent view acts as border color. It looks ugly in IB, it cannot layout views properly but resulting layout on device looks perfect.
In interface builder:
On simulator:
Constraints are a bit tricky. For each row:
set height for the 1st button
set equal height for all buttons
set equal width for all buttons (a bit different for rows with orange buttons)
align top edges of all buttons
align bottom edges of all buttons
set leading and trailing spaces between all buttons (including spaces to superview) to 0.5
set top space (to previous row) of 1st button to 0.5
You can apply constraints to multiple items at once. In order to apply leading/trailing spaces between buttons, place them without intersection in desired order before applying.
I want to set a background image to uiview with multi region like picture below?
How can i do that?
(constant)
<----->
+------------------+ ^
| | | | | (constant)
| A | | B | |
|-----+ - - +------| v
| | | | ^
| | | | |
| C | | D | | (stretched region)
| | | | |
| | | | |
+------------------+ v
<—————> <——————>
(stretched region)
Update: This is my image http://i.imgur.com/mEk75Sc.png
Use multiple images for each region.. this will be easier.
I originally tried doing this with two UICollectionViews stacked on top of each other. However getting it to scale right was nightmare with Auto-layout (I'm a novice iOS developer so that is more a critique of my skill than Auto-layout). I'd like to stack two sections of UICollectionView cells on top of each other like this:
+----------------------+
|+-Section 0---------->|
| +-------+ +-------+ |
| | | | | |
| | | | | |
| |Cell 0 | |Cell 1 |+->
| | | | | |
| | | | | |
| +-------+ +-------+ |
+--Section 1---------->|
| +-------+ +-------+ |
| | | | | |
| | | | | |
| | | | | |
| |Cell 0 | |Cell 1 |+->
| | | | | |
| | | | | |
| +-------+ +-------+ |
| |
+----------------------+
I'm using a custom Flow Layout, but I'm not even sure where to begin breaking my current 2 sections to stack like this. Currently my sections are stacked like this:
+--------(Offscreen)
|
+
+--------xxxx--------+v
| Section 1 | Section 2
| +-----+ +-----+ | +-----+ +-------+
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| +-----+ +-----+ | +-----+ +-------+
| |
| |
| +-----+ +-----+ | +-----+ +-------+
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| +-----+ +-----+ | +-----+ +-------+
| |
| |
| xxxx |
+--------xxxx--------+
UICollectionView can scroll either vertical or horizontal not both. If you have only two sections like in the diagram you can use two collection view. But it better to think of a design like a table view contains collection views in each cells. So that the design will be flexible(Horizontal and vertical scrolling with any number of sections). Anyway the design is little bit complex, you should customize the table view cell to put collection view in it. Now the UITableView will give you vertical scrolling with the ability to scroll each rows horizontaly(UICOllectionView)
I am trying to debug a UI Layout and all the elements I have added in the code are labelled with [self.element setTranslatesAutoresizingMaskIntoConstraints:NO]; The only thing that is set in XIB file is the background color of the view (one of many views in a tabbed viewController.
When I look at the NSLog I am seeing the following:
*<UIWindow:0xc352370> - AMBIGUOUS LAYOUT
| *<UILayoutContainerView:0xc3651b0>
| | *<UINavigationTransitionView:0xc355b40>
| | | *<UIViewControllerWrapperView:0xbd3e250>
| | | | *<UILayoutContainerView:0xbd3da60>
| | | | | *<UITransitionView:0xbd46ed0>
| | | | | | *<UIViewControllerWrapperView:0xc09a450>
| | | | | | | *<UIView:0xbd51f40>
| | | | | | | | *<_UILayoutGuide:0xbd51fa0> - AMBIGUOUS LAYOUT
| | | | | | | | *<_UILayoutGuide:0xbd50a10> - AMBIGUOUS LAYOUT
| | | | | | | | *<UIButton:0xc064170> - AMBIGUOUS LAYOUT
| | | | | | | | | *<UIButtonLabel:0xc09d640>
| | | | | | | | *<UILabel:0xc073990> - AMBIGUOUS LAYOUT
| | | | | | | | *<UIButton:0xc0576a0> - AMBIGUOUS LAYOUT
| | | | | | | | | *<UIButtonLabel:0xc095290>
| | | | | | | | *<UIButton:0xc096640> - AMBIGUOUS LAYOUT
| | | | | | | | | <UIButtonLabel:0xc096820>
| | | | | | | | *<UIButton:0xc098b70> - AMBIGUOUS LAYOUT
| | | | | | | | | <UIButtonLabel:0xc098cb0>
| | | | | | | | *<UIButton:0xc09a4c0> - AMBIGUOUS LAYOUT
| | | | | | | | | <UIButtonLabel:0xc09a6d0>
| | | | | | | | *<UILabel:0xc09c9d0> - AMBIGUOUS LAYOUT
| | | | | | | | *<UILabel:0xc09cc60> - AMBIGUOUS LAYOUT
| | | | | | | | *<UIButton:0xc09ce00> - AMBIGUOUS LAYOUT
| | | | | | | | | <UIButtonLabel:0xc09d010>
| | | | | | | | *<UILabel:0xc0a25f0> - AMBIGUOUS LAYOUT
| | | | | | | | *<UIButton:0xc0a2800> - AMBIGUOUS LAYOUT
| | | | | | | | | <UIButtonLabel:0xc0a2a10>
| | | | | | | | *<UILabel:0xc0a5720> - AMBIGUOUS LAYOUT
| | | | | <UITabBar:0xc356c00>
| | | | | | <_UITabBarBackgroundView:0xbe28cc0>
| | | | | | | <_UIBackdropView:0xbe29100>
| | | | | | | | <_UIBackdropEffectView:0xbe296e0>
| | | | | | | | <UIView:0xbe29780>
| | | | | | <UITabBarButton:0xbd42000>
| | | | | | | <UITabBarSwappableImageView:0xbd41050>
| | | | | | | <UITabBarButtonLabel:0xbd43320>
| | | | | | <UITabBarButton:0xbd462e0>
| | | | | | | <UITabBarSwappableImageView:0xbd45d60>
| | | | | | | <UITabBarButtonLabel:0xbd45c70>
| | | | | | <UITabBarButton:0xbd47770>
| | | | | | | <UITabBarSwappableImageView:0xbd48a90>
| | | | | | | <UITabBarButtonLabel:0xbd486c0>
| | | | | | <UITabBarButton:0xbd4c0c0>
| | | | | | | <UITabBarSwappableImageView:0xbd4c220>
| | | | | | | <UITabBarButtonLabel:0xbd4aea0>
| | | | | | <UIImageView:0xbe29ed0>
| | <UINavigationBar:0xc06c4a0>
| | | <_UINavigationBarBackground:0xc05e720>
| | | | <_UIBackdropView:0xc357d70>
| | | | | <_UIBackdropEffectView:0xc3639a0>
| | | | | <UIView:0xc355470>
| | | | <UIImageView:0xc071980>
| | | <UINavigationItemView:0xc074c80>
| | | | <UILabel:0xc083730>
| | | <_UINavigationBarBackIndicatorView:0xc36edb0>
po [
(lldb) po [0xbd51fa0 constraintsAffectingLayoutForAxis:0]
<__NSArrayM 0xbd39190>(
)
(lldb) po [0xbd50a10 constraintsAffectingLayoutForAxis:0]
<__NSArrayM 0x1121f8f0>(
)
(lldb) po [0xc064170 constraintsAffectingLayoutForAxis:0]
<__NSArrayM 0xc0a14e0>(
<NSLayoutConstraint:0xc093aa0 H:|-(NSSpace(20))-[UIButton:0xc064170] (Names: '|':UIView:0xbd51f40 )>,
<NSLayoutConstraint:0xc093b30 UIButton:0xc064170.width == UIButton:0xc0576a0.width>,
<NSLayoutConstraint:0xc093be0 H:[UIButton:0xc064170]-(20)-[UILabel:0xc073990]>,
<NSLayoutConstraint:0xc093c10 UILabel:0xc073990.width == UIButton:0xc0576a0.width>,
<NSLayoutConstraint:0xc096530 H:[UILabel:0xc073990]-(20)-[UIButton:0xc0576a0]>,
<NSLayoutConstraint:0xc096590 H:[UIButton:0xc0576a0]-(NSSpace(20))-| (Names: '|':UIView:0xbd51f40 )>,
<NSAutoresizingMaskLayoutConstraint:0xc0af130 h=--& v=--& H:[UIView:0xbd51f40(768)]>
)
(lldb) po [0xc09a4c0 constraintsAffectingLayoutForAxis:0]
<__NSArrayM 0xc36a0a0>(
<NSLayoutConstraint:0xc09c9a0 H:|-(<=0)-[UIButton:0xc09a4c0] (Names: '|':UIView:0xbd51f40 )>,
<NSContentSizeLayoutConstraint:0xc0ad530 H:[UIButton:0xc09a4c0(110)] Hug:250 CompressionResistance:750>
As you can see from po commands, I am getting NSAutoresizingMasktLayoutContraints. I thought this shouldn't happen?
How can I ensure that I don't get this?
Ok.. I have figured out that the constraints did not appropriately address the relationship between each other. I have updated the code and now I can get clean constraints for all aspects, except for the main UIWindow, which I am sure is just because of the problem with the UILayoutGuide being ambiguous -
*<UIWindow:0xcc6d7f0> - AMBIGUOUS LAYOUT
| *<UILayoutContainerView:0xbd34720>
| | *<UINavigationTransitionView:0xbd4b140>
| | | *<UIViewControllerWrapperView:0xcc48400>
| | | | *<UILayoutContainerView:0xbd5ad40>
| | | | | *<UITransitionView:0xbd635c0>
| | | | | | *<UIViewControllerWrapperView:0xcca68b0>
| | | | | | | *<UIView:0xcc9ddd0>
| | | | | | | | *<_UILayoutGuide:0xcc9de30> - AMBIGUOUS LAYOUT
| | | | | | | | *<_UILayoutGuide:0xcc9e090> - AMBIGUOUS LAYOUT
| | | | | | | | *<UIButton:0xcc9d910>
| | | | | | | | | <UIImageView:0xcc9dd20>
| | | | | | | | *<UILabel:0xcc9e860>
| | | | | | | | *<UIButton:0xcc9ebb0>
| | | | | | | | | <UIImageView:0xcc9eda0>
| | | | | | | | *<UIButton:0xcc9f020>
| | | | | | | | | <UIButtonLabel:0xcc9f470>
| | | | | | | | *<UIButton:0xcca0620>
| | | | | | | | | <UIButtonLabel:0xcca0830>
| | | | | | | | *<UIButton:0xcca15d0>
| | | | | | | | | *<UIButtonLabel:0xcca17e0>
| | | | | | | | *<UILabel:0xcca2580>
| | | | | | | | *<UILabel:0xcca2710>
| | | | | | | | *<UIButton:0xcca28d0>
| | | | | | | | | *<UIButtonLabel:0xcca2ae0>
| | | | | | | | *<UILabel:0xcca3880>
| | | | | | | | *<UILabel:0xcca3bd0>
| | | | | | | | *<UIButton:0xcca3e30>
| | | | | | | | | *<UIButtonLabel:0xcca4040>
| | | | | | | | *<UILabel:0xcca4de0>
| | | | | | | | *<UILabel:0xcca5000>
| | | | | <UITabBar:0xcc69e40>
| | | | | | <_UITabBarBackgroundView:0xcccad10>
| | | | | | | <_UIBackdropView:0xcccb150>
| | | | | | | | <_UIBackdropEffectView:0xcccb730>
| | | | | | | | <UIView:0xcccb7d0>
| | | | | | <UITabBarButton:0xcc96bf0>
| | | | | | | <UITabBarSwappableImageView:0xcc8d330>
| | | | | | | <UITabBarButtonLabel:0xcc8d270>
| | | | | | <UITabBarButton:0xcc98830>
| | | | | | | <UITabBarSwappableImageView:0xcc81840>
| | | | | | | <UITabBarButtonLabel:0xcc983a0>
| | | | | | <UITabBarButton:0xcc9a050>
| | | | | | | <UITabBarSwappableImageView:0xcc8e3e0>
| | | | | | | <UITabBarButtonLabel:0xcc9a130>
| | | | | | <UITabBarButton:0xcc9a560>
| | | | | | | <UITabBarSwappableImageView:0xcc9b140>
| | | | | | | <UITabBarButtonLabel:0xcc9aa20>
| | | | | | <UIImageView:0xcccbf20>
| | <UINavigationBar:0xbd27340>
| | | <_UINavigationBarBackground:0xbd2fc60>
| | | | <_UIBackdropView:0xbd43740>
| | | | | <_UIBackdropEffectView:0xbd2c200>
| | | | | <UIView:0xbd46100>
| | | | <UIImageView:0xbd2ffd0>
| | | <UINavigationItemView:0xbd1e270>
| | | | <UILabel:0xbd283c0>
| | | <_UINavigationBarBackIndicatorView:0xbd566e0>
The UILayoutGuide is not set anywhere in my code, so I am not quite sure what do with it.