Enlarging ImageSlider on Tap in Swift iOS - uiimageview

I want to have 3 ImageSliders stack on top of each other, not overlay, like 3 sliders one on top, one in the middle, and one at the bottom. When you tap on one, it resizes to 30% larger in Height and Width, once you tap another one, the current one resizes back to 30% smaller and the new one which got tapped enlarges 30% in size. How can I make such thing in Swift ? I tried to google some solution but haven't find any tutorial or answer.

It's a bit complicated, but you can experiment with the following API which can be used on any view, including the UISlider.
imageView.transform = CGAffineTransformMakeScale(1.3, 1.3)
This can also be animated by including it into a UIView animation block (see documentation about animateWithDuration).

Related

Xcode auto alignment and constraints - equal distances between several images

I have nine images ad I want them to display in a single column on the device. The images should retain their original height and width (that I will set) and the only thing that should change according to the screen height should be the distance between the images.
I'm not really sure how to approach this problem - I tried using a container, but it didn't turn out as I expected. Should I set the constraints programmatically? And if so, how? What should the constraints be if I want the images to be from top to bottom of he screen?
Consider using a stack view:
On iOS, UIStackView provides UIStackViewDistributionEqualSpacing, which I believe will arrange images as you want
On Mac, NSStackView can automatically space images as you describe if the individual image views are all in the same gravity and retain their sizes at a high enough priority (using constraints or content hugging priority)

Bootstrap Carousel image height causes scroll bars on smaller screens

I'm very new to bootstrap, and programming in general so please be patient! I have literally spent hours trying to find a solution to my problem via here/google, and the time has come to ask for some help!
Basically, I am trying to make a website for displaying photos in a carousel. I want my site to be responsive so it works on smaller devices. All my original images are the same size/dimensions (2304 x 1728 so 4:3, probably too big) and use the img-responsive class.
It looks fine on a large screen, but when I try it on smaller laptop screens and tablets, the image height causes scrollbars to appear so you can't see the bottom of the image/caption. However, the image width is responsive and shrinks to fit without scrolling.
I am of the understanding that the carousel size is dictated by the image size, so the logical solution would be to make my image size smaller in height - but I need to maintain the aspect ratio, and smaller images didn't look so good. I also tried setting a fixed height as a style but it didn't work.
What is the ideal image size (in px) for a carousel which takes up most of a browser window (allowing for navbar/header/footer), and how do you make it so the height doesn't require scrollbars?
Many thanks in advance!
My answer may not be accepted by everyone , but I think the only flaw of bootstrap is precisely the Bootstrap Carousel
Can not be changed easily (since as you say you do not have much programming experience), and does not offer a lot of customization
So I think the best solution for your problem is Owlcarousel , offers hundreds of customization options
OWL Carousel
Touch enabled jQuery plugin that lets you create beautiful responsive carousel slider.

Autolayout - equal distribution of 6 views

I want to have 6 objects (buttons) laid out inside one view. They should, however, follow some constraints:
Two top buttons should have the same vertical distance from superview (A)
Two bottom - the same (C)
Two in the middle should have their centers at the superview's center line
The vertical distances between all buttons (E) should be the same
and last but not least - the buttons should be square (so the width and height should be the same)
A = C
B = D
Is it possible to have this effect just in the IB, or should I use some additional code for the constraints?
This is a logical request, but constraints are defined using the attributes of views, but cannot not be defined in relation to other constraints. That having been said, there are a number of approaches:
Layout guides: An approach which doesn't require predetermining the any spacing is to have UILayoutGuide objects or, if using iOS versions before 9, just use hidden views, i.e. views with clear background or alpha of zero, in between the buttons.
The idea is to add these layout guides with addLayoutGuide (or add invisible views with addSubview if supporting iOS versions predating iOS 9) in between your six buttons as "spacers", and define the spacers to be the same size as each other, and with constraints between the spacers, the superview, and the buttons that will go in between the spacer. Once you lay that out (showing the horizontal spacer views in blue, vertical ones in red, just so you can see them):
The equivalent VFL for the constraints for those red UIView objects, called vspacerX, would be:
H:|[vspacer1][button1(100)][vspacer2(==vspacer1)][button2(==button1)][vspacer3(==vspacer1)]|
H:|[vspacer1][button3(==button1)][vspacer2][button4(==button1)][vspacer3]|
H:|[vspacer1][button5(==button1)][vspacer2][button6(==button1)][vspacer3]|
And constraints on the blue UIView objects, called hspacerX, like:
V:|[hspacer1][button1(100)][hspacer2(==hspacer1)][button3(==button1)][hspacer3(==hspacer1)][button5(==button1)][hspacer4(==hspacer1)]|
V:|[hspacer1][button2(==button1)][hspacer2][button4(==button1)][hspacer3][button6(==button1)][hspacer4]|
You don't have to use VFL to define these constraints, as any way you define these constraints will work, but it's just a concise format for describing the collection of constraints that I employed.
Anyway, when the view is rendered with those layout guides (or invisible views), it yields evenly spaced buttons like so:
Another approach is to have six "container" views, that would look like:
The equivalent VFL for these six container UIView objects might look like:
H:|[container1][container2(==container1)]|
H:|[container3(==container1)][container4(==container1)]|
H:|[container5(==container1)][container6(==container1)]|
V:|[container1][container3(==container1)][container5(==container1)]|
V:|[container2(==container1)][container4(==container1)][container6(==container1)]|
You can then add your buttons to that, centering one on each of the six little containers and then make your containers clear:
This works, too, but just a slightly different spacing (where the margins are half of the spacing between the views, whereas the other approach keeps the margins the same as the spacing between them.
Stack view: In a permutation of the prior point, in iOS 9, you can also use UIStackView, designed precisely for evenly spacing views. In this case, put two buttons each in three horizontal stack views, and then place those stack views within a vertical stack view. This achieves six evenly sized container views.
See WWDC 2015 video What's New in Cocoa Touch.
The problem with stack views is that they can be used to ensure even spacing between the arranged subviews, they don't ensure spacing before the first arranged view nor after the last arranged view. So, the kludge to get around that is to, for horizontal stack view, include two more zero width views (or zero height for vertical stack views). Then when you use even spacing on the stack view, it also give you what will appear to be spacing before and after all of the arranged subviews.
NSLayoutAttributeCenterX with multiple: Another technique involves defining the attribute:NSLayoutAttributeCenterX and attribute:NSLayoutAttributeCenterY attributes for your six buttons, but rather than using the constant values, use the multiplier field. This technique enjoys a little simplicity, but doesn't always render the desired effect, so I won't describe it unless it's something you definitely want to pursue. I've already entered tl:dr territory here.
Collection view: Another approach is to use a UICollectionView, which handles this scenario gracefully. It's well designed to let you layout cells in a grid.
Hardcoding values: For the sake of completeness, I'll note that you could simply specify specific values for A, B, C, and D (as well as the width and height constraints). You don't even have to worry about setting the E constraints, but rather just set the vertical center constraint of the middle two to their superview, and you're effectively done (because the spacing represented by E should be a natural result of the previous steps, assuming A=C and B=D). If you want to adjust these values on the basis of device size and/or orientation, you can then implement a viewWillLayoutSubviews to adjust the constants for these constraints according to the size of the view.
Update: I have a better solution that does not use spacers. Check it out here.
Ok, this can be achieved very quickly in IB. It's so so simple. Here's a diagram that will help illustrate.
Assume v1-6 are your buttons, and s1-5 are your spacers.
1) in IB control drag out all of the connections shown by the red lines.
2) shift click v1-6 and pin icon (looks like |-I-| ) set the width and height to a definite value. also, set the height and width to be equal.
3) shift select s1-4 (not 5) and set the height to equal. do not give it a definite height, since this should be calculated by the system. you might also need to set the widths of s1-4 to be equal, but don't give them a definite width.
4) control drag from the centre views to the leading and trailing edge and set the centre constraint.
So, you might think, ok, this should work now. It doesn't. Here's my app running in portrait with slightly different colors. Looks good. (Notice, you would make the spacers invisible once you get it setup).
But when I rotate, oops!
What's happening here? The problem is incredibly easy to solve once we understand what's gone wrong. What we want is for IB to not shrink our views. We want IB to make the spacers and the spaces to shrink and grow as necessary, but to leave our views alone. Basically, IB has shrunk the spacers down as far as it can in portrait and to attempt to make everything fit IB has shrunk our views. But we wanted IB to shrink the vertical spaces between views and spacers, not our views. The solution is so easy. All we have to do is adjust the priority of the vertical spaces and all is well. So, select the vertical spaces in IB and adjust the priority to 750. The vertical spacing lines will show as dashed. Done.
Ok, so here's everything as we expect it.
And with the spacers made clear:

Fixed div that moves vertically at 2x scrollspeed when scrolling

I would like to make a div move down on scroll but at a faster rate (i.e. if the user scrolls 200px down the div will smoothly scroll 400px down.)
Basically a fixed div that moves up and down at 2x (maybe less) rate of the scroll speed
I have searched a lot for an answer but no luck so I hope one of you bright minds can help me.
If you need me to be more specific I can make a video or an illustration that clarifies what I'm trying to do.
You are looking to do a parallax scrolling effect. There are lots of js libraries that can do this, one of them is: Stellar.js
Nike also made a temporary site (Better World) that had this effect.

Buttons become mis-aligned when window is resized

I'm designing my interface in Interface Builder (using Xcode 4.2 on Snow Leopard), and PERFECTLY aligning two elements (two NSButtons, bordered), one below the other.
The thing is that when the window is resizing, at some points, the elements seem misaligned (by 1 pixel or so), while at some other, they're still perfectly aligned.
Here's a (zoomed) example of what I mean:
Aligned
Mis-Aligned
And here are my resizing settings (for the upper NSButton):
And for the container (of my upper NSButton):
I know I'm probably getting a bit too crazy about such a tiny issue, but I definitely need to resolve it.
So, why is that happening? What should I do in order to resolve it?
Are both buttons in the same container?
Do they have the same size & alignment settings?
Below the autosizing widgets in the inspector, there's a set of alignment buttons. Try selecting both buttons and clicking the left-side alignment button. (See if that makes the other side mis-align.) Below that are placement icons - verify both buttons have same settings there.
Type in values for W & H so both buttons are the exact same (even if the boxes already show the same, type over it to be sure). Also type in X & Y so they're same (except for vertical offset).
Personally, having the center scaling set (last image, double-ended horizontal arrow) seems odd when it's only anchored on one side. That might have a strange effect. On the other hand, you have both vertical anchors set but not the vertical scaling.
If all else fails, you could try (save original version first) delete the second button, copy the first and position the copy below it.

Resources