I hope this question makes sense.
I have 2 images in my viewcontroller. One is for a background and the second I need to move around on top of that image freely. I am using autolayout for the background image, but when I test on different devices the second image is not in the proper place because I am not using the autolayout on it and therefore it does not move correctly.
How can I move the image to be in the proper place. Is there some way to set it properly in code. I guess I mean how could I set the autolayout in code since this image will have many positions it needs to move to.
Related
I currently face a problem when using UIButton. I have the background image designed by others like this:
background image
and I need to place the title for the button right after the white vertical bar in the background image. I tried to set left edge for the content but since I used auto layout, the frame will be different with different screen size(3.5", 4.7"...).
Is there a way to put text in the position related to background I want with auto layout.
Thanks
I personally would split the left side of the background image from the right side. This way you can have two UIButtons next to each other with horizontal space constraint of 0. The right side of the button will have to be placed inside a UIImageView so you can set the image as a property of the view rather that the button's background. You don't have to do this of course, but I prefer this solution as it is easier to manage across different screen sizes.
Here is a visual representation of what I explained above:
Separated Views for Single UIButton
You will then need to route the touch events of both buttons to run the same method or function, just so that both the right side and the left are clickable.
Note: I'm not sure exactly what you had in mind for the highlighting of the button, but this will have to be tested and adapted to get the desired effect.
I'm trying to do a rounded images to be shown in my WatchKit application but I don't find any method to do it programatically.
What I have done to perform that, it is use my original image as a group background and put inside a mask image with rounded shape but I think this is not so clean.
Another different solution that I have thought is to create in my backend a new thumbnail or similar with the shape I want to show, but this require more time to be programed.
I could use also radius parameter from WKInterfaceGroup but, in my case (see the image below), I will lose my notification bubble that I have in a corner.
My app interface:
Uber application example:
Put your WKInterfaceImage inside a WKInterfaceGroup and round the corners of the group in Interface Builder.
What you are trying to create is not possible at the moment (we'll see if Apple will add new features to WatchKit this Summer). You'll need to mask your icons on your device and cache on your Watch.
As 'bgilham' said you could put the WKInterfaceImage inside WKInterfaceGroup, but you don't have to. You can just set the background image of WKInterfaceGroup. This time you can create some shiny fake subviews. WKInterfaceGroup inside WKInterfaceGroup with different background images on them.
For example. Lets say you have three ui (WKInterface) elements 'iconGroup', 'badgeGroup', 'badgeLabel'.
Center badgeLabel inside badgeGroup. Set badgeGroups radius to half of its height. If badgeGroups width is equal to its height you'll get a nice circle. Place your badgeGroup inside iconGroup at the top right corner. You can now set the radius of iconGroup equal to the radius of badgeGroup. Set the background image and you'll get a nice rounded rectangle with an dynamic badge.
You also can hide some items (groups) and fake some dynamic changes inside your watch app. There is tons you can create with such fakes. If you will add some animations (for example .png files) you can create fake views with transparent overlays and so on.
UPDATE:
I checked the uber screenshots of uber app, because I was wondering how they created that overlay over the map. My only clue is that they creating a lot of images on their iPhone and sending them to the apple watch to animate the background image of the WKInterfaceGroup. If the images are cached they will play 30fps on the watch otherwise its going to be 10fps or so.
My statement:
So rethink your design, its not always good to make a design like everyone else do. Create something shiny and new so people will memorize your work. :)
Hope this will help you guys out there to rethink your work and create some cool watch apps. Day one apps aren't that great at all, only a few of them are.
You can actually achieve this by using three groups:
The 1st WKInterfaceGroup has your original non-cropped image as its background.
The 2nd WKInterfaceGroup, which is inside the 1st one but has the same size, has the circle image mask as its background.
The 3rd WKInterfaceGroup, which is inside the 2nd one, contains your badge. You can put the text label in it.
Although this requires a pure simple background so the mask image can simply just overlay above the background image, this one doesn't require any image data transferring between the phone and the watch.
The only way to do this right now is just as you said. To mask the profile image into a circle, add it to a group, then add the notification bubble group as a sub-group of the main one (with a circular radius and the label inside.)
Right now there is no way to have a sub-group ignore its parent's clipping radius.
i have used UIImage category from http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/.
this has a Category for Rounded corner images, worked for me in watchkit app.
I have issue with autolayout.
I have three different views (could be n views as well). When I pin first one to top of super view and connect one next to the other everything seems fine. But if I want to change height of first one the other two does not follow (they stay on the same position). What I find weird about this is that if I connect only two views this works perfectly.
To have better understanding what I am trying to achieve I made simple, example solution with three views:
http://i.stack.imgur.com/cMwiB.png
So, when I set height of green view to 0 ( can be any other number as well ) and only red view is connected, this works fine, red will move as it should. Blue one is not connected and it remains where it is:
Here is screenshot when I connect blue to red:
What I tried to do:
connect blue one to green as well ( not working)
connect blue only to green ( not working )
"boxing": have boxes with views at the time ( ugly, hard to manage, not working in all cases)
What I would like to know:
what makes this happen? Can I change this kind of behavior?
What is the best practice to have flexible length for height (Besides UITableView)
Thanks in advance.
Ok, I think you're falling into the same trap I did, when I investigated autolayout some time ago. It's tricky to explain, but I'll do my best. When you work with autolayouts, you need to forget completely about setting a view's frame at all. And that, my friend, includes changing size and positioning. When you use autolayout, you define some constraints, some "rules", that the view tries to respect when rendering the screen, so the more specific the rules are, the less random will be the behavior of the view. I mean, if you just define the spacing between views, you're implying that the height of the views doesn't matter, so it's possible that some views grow or shrink when the re-layout is called (that is, if you don't specify a constraint for size. You probably want to always specify the size of some views in every layout...)
By the way, you're allowed to violate the constraints by manually changing the frame of an element AFTER a re-layout is called, but when the re-layout method is called again, the constraints will be forced so the size and positioning of the views will change. Quick tip: an easy way to force the re-layout method is to change orientation (command+left / command+right in the simulator).
So after saying that, I have to say that the layout you provided is completely working as intended, at least to me. When you change orientations the constraints you specified are ALWAYS being respected. If you want, you can try to apply some frame-setting in the viewDidAppear method, because this one is called AFTER the autolayout (and thus, you're able to violate the constraints temporally). After doing this, your view will be broken but once you change orientation the constraints should be respected again. Make sure it's that way.
From here I can only wish you luck ;) Oh, and refer to the documentation, it was a life saver to me when I looked at this half a year ago. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html It might seem a classic, but it's a pretty nice doc.
EDIT: one last thing. I have the impression that constraints are not designed to be dynamic. You define them once, and they're there always. Their main purpose is to ensure that subviews are rendered as intended in every screen resolution without fail, so if I were to make an application with moving views, I would leave them outside of the autolayout, or avoid using it at all. Just a personal impression though :)
I have a VC with two imageViews. One takes up the whole screen, the other is actually slightly larger and can be moved around on the screen (Pan Gesture).
When the device changes orientation only the static view changes orientation, or just updates its frame maybe (automatically).
The second Pan UIImageView does not move. Is there a reason for this, or a switch to make this happen somewhere possibly in the storyboard properties of the UIImageView itself? I would like the view to move too.
I understand that an option would be to use the methods that confirm the orientation has completed a change and transform the imageView myself, which is not a problem... but checking I am not missing something that could do this for me automatically first.
Ensure you are using correct AutoResizeMasks on the imageview. Provide your code or storyboard description for a more complete answer.
-Additionally if you are using AutoLayout, you may need to add the appropriate constraints (making it slightly larger than the view may confuse it as to your intention without proper suggestions via constraints).
I find myself often having to reposition subviews of a view after hiding or showing one of them. The way I'm doing this is by programmatically changing a view frame's origin and/or size, or its center. But is there an easier way I'm missing? Is there a way to do it with Autosizing masks?
I don't think there's any automatic way of doing this. You could probably get clever about how you do it programmatically (e.g. if you used a set of sequential tag identifiers, you could loop through and calculate the height of the previously visible tag to calculate the origin of the next subview; or if there are a group of subviews that are always going to move together, you could put them in a container UIView and thus move a whole bunch of them by just moving their container view; etc. ... it depends upon how they're laid out and which fields might be hidden).
This won't help you for now, but check out WWDC 2012 session 202 for a discussion of a relevant improvement in iOS 6.