For some reason, I have searched high and low, and cannot find the exact image sizes that I need to supply for a background image for both the 38mm and 42mm sizes in Watchkit. Currently I am stretching a smaller image using "scale to fill".
I don't want it stretched, so I am looking for real pixel sizes.
Here is the code I use to get the size for the background image in my WKInterfaceController. My app has a page control, you you probably don't want the extra -14 at the end.
-(CGSize)backgroundSize
{
CGRect contentFrame = self.contentFrame;
CGSize size = contentFrame.size;
CGFloat contentScale = 2.0;
size.width *= contentScale;
size.height *= contentScale;
//I lined up the generated image with one in the simulator until
//they perfectly matched. I did this on both 38 and 42 mm.
//I am not sure why they all came out to be off 4.
//There is an offset of 10 in IB and I am not sure I need this
//to be 4 to match perfect.
size.height -= 4;
//it looks like there is 2 pixels around the edge
size.width -= 4;
//Using page mode we need to take off an additional 14 pixels for the page dots at the bottom
size.height -= 14;
return size;
}
Related
I am new in Corona SDK and I have a problem,
when I place an image at the top of the screen, there is an empty space, how can I make it disappear?
thanks!
It all depends on which device you are running an app. Some of them are taller, some are wider. So there's a value display.screenOriginY which has to be added to a y value if you place an object in a distance from top of screen.
Here's more info:
https://docs.coronalabs.com/api/library/display/screenOriginY.html
In your config.lua file, you can make Corona fill the entire device screen by setting scale = "adaptive". You can read more about adaptive content scaling here
When you use this adaptive scaling, the coordinate (0,0) will be the upper left of the device screen. However, the width and height will vary from device to device and you have to take this into account in your code. You can get these parameters using display.contentWidth and display.contentHeight.
Try (point (0, 0) is located in upper top corner od screen)
--calculate the aspect ratio of the device
local aspectRatio = display.pixelHeight / display.pixelWidth
application = {
content = {
width = aspectRatio >= 1.5 and 800 or math.floor( 1200 / aspectRatio ),
height = aspectRatio <= 1.5 and 1200 or math.floor( 800 * aspectRatio ),
scale = "letterBox",
fps = 30,
imageSuffix = {
["#2x"] = 1.3,
},
},
}
I'm having trouble understanding how I make my SKSpriteNode fit each iPhone. I have a background image and a separate chair image that needs to be in the same position and scalling for each iPhone. When I get it to look good on say the 6+ if I swap to a 5s its not in the correct position and isn't scaled for that iPhone. This is how I am currently scaling and positioning my SKSpriteNode.
chair.position = CGPointMake(self.size.width * 0.50, self.size.height * 0.35)
chair.setScale(0.50)
chair.zPosition = 1.0
self.addChild(Chair)
I guess you have a problem of screen scale factors which are different from iPhone 5s (x2) to iPhone 6+ (x3). Simply multiply with screen factor you may solve the problem. The code (Swift) looks like bellow:
let screenScaleFactor = UIScreen.mainScreen().scale
chair.position = CGPointMake(self.size.width * 0.50 * screenScaleFactor, self.size.height * 0.35 * screenScaleFactor)
chair.setScale(0.50 * screenScaleFactor)
chair.zPosition = 1.0
self.addChild(Chair)
I have tried searching this functionality but didn't solved my problem.
What I Want: I have a UILabels text as "attended" with initial font size of 28 (totally four labels with different fonts sizes and texts). Now I vary slider (which is placed in the bottom), I will send the font size to be increased or increased. Now, i want to not only change the font size but also UILabel frame like
self.labelAttendCount.frame = CGRectMake(40 + (diff * 0.7) , 110 - (diff * 0.3), 40 - diff/5, 30 - (diff * 0.3))
self.labelAttendCount.font = UIFont(name: "ArialMT", size: round(28 - (diff * 0.28)))
Everything goes fine but, when its position is changing its jerky (or shaky). I want this to be dealt smoothly.
refer to this link where there is smooth increase or decrease in label size. http://macoscope.com/blog/ios-7-dynamic-type-simulator-for-designers/
Hope u understand my question.
Please check this shared video link (removed link)
This solution might be usefull for some one.
Finally got a Solution to shrink UILabel or UIButton Text and change their position:
Make UILabels as subview to UIView.
viewLeft.addsubView(labelAttendedCount)
later
viewLeft.transform = CGAffineTransformMakeScale(1 - (diff * 0.01), 1 - (diff * 0.01)) // to shrink viewLeft UIView
viewLeft.frame = CGRectMake(25 + (diff * 0.8), 110 - (diff * 0.3), 100 , 50 - diff/2) // to move the ViewLeft and diff is increase in the contentoffset or UIPanGesture location.y
viewLeft.center = CGPointMake(25 + viewLeft.frame.width/2 + (diff * 0.8), viewLeft.frame.origin.y + viewLeft.frame.height/2) // To adjust the position of the UIView.
Instead of changing the font size, you can just use UIView's transform, e.g
self.labelAttendCount.transform = CGAffineTransformMakeScale(1.5, 1.5);
I am working on a few experiments to learn gestures and animations in iOS. Creating a Tinder-like interface is one of them. I am following this guide: http://guti.in/articles/creating-tinder-like-animations/
I understand the changing of the position of the image, but don't understand the rotation. I think I've pinpointed my problem to not understanding CGAfflineTransform. Particularly, the following code:
CGFloat rotationStrength = MIN(xDistance / 320, 1);
CGFloat rotationAngle = (CGFloat) (2 * M_PI * rotationStrength / 16);
CGFloat scaleStrength = 1 - fabsf(rotationStrength) / 4;
CGFloat scale = MAX(scaleStrength, 0.93);
CGAffineTransform transform = CGAffineTransformMakeRotation(rotationAngle);
CGAffineTransform scaleTransform = CGAffineTransformScale(transform, scale, scale);
self.draggableView.transform = scaleTransform;
Where are these values and calculations, such as: 320, 1-fabs(strength) / 4 , .93, etc, coming from? How do they contribute to the eventual rotation?
On another note, Tinder seems to use a combination of swiping and panning. Do they add a swipe gesture to the image, or do they just take into account the velocity of the pan?
That code has a lot of magic constants, most of which are likely chosen because they resulted in something that "looked good". This can make it hard to follow. It's not so much about the actual transforms, but about the values used to create them.
Let's break it down, line by line, and see if that makes it clearer.
CGFloat rotationStrength = MIN(xDistance / 320, 1);
The value 320 is likely assumed to be the width of the device (it was the portrait width of all iPhones until the 6 and 6+ came out).
This means that xDistance / 320 is a factor of how far along the the x axis (based on the name xDistance) that the user has dragged. This will be 0.0 when the user hasn't dragged any distance and 1.0 when the user has dragged 320 points.
MIN(xDistance / 320, 1) Takes the smallest value of the dragged distance factor and 1). This means that if the user drags further than 320 points (so that the distance factor would be larger than 1, the rotation strength would never be larger than 1.0. It doesn't protect agains negative values (if the user dragged to the left, xDistance would be a negative value, which would always be smaller than 1. However, I'm not sure if the guide accounted for that (since 320 is the full width, not the half width.
So, the first line is a factor between 0 and 1 (assuming no negative values) of how much rotation should be applied.
CGFloat rotationAngle = (CGFloat) (2 * M_PI * rotationStrength / 16);
The next line calculates the actual angle of rotation. The angle is specified in radians. Since 2π is a full circle (360°), the rotation angle is ranging from 0 and 1/16 of a full circle (22.5°). Th value 1/16 is likely chosen because it "looked good".
The two lines together means that as the user drags further, the view rotates more.
CGFloat scaleStrength = 1 - fabsf(rotationStrength) / 4;
From the variable name, it would look like it would calculate how much the view should scale. But it's actually calculating what scale factor the view should have. A scale of 1 means the "normal" or unscaled size. When the rotation strength is 0 (when the xDistance is 0), the scale strength will be 1 (unscaled). As rotation strength increase, approaching 1, this scale factor approaches 0.75 (since that's 1 - 1/4).
fabsf is simply the floating point absolute value (fabsf(-0.3) is equal to 0.3)
CGFloat scale = MAX(scaleStrength, 0.93);
On the next line, the actual scale factor is calculated. It's simply the largest value of the scaleStrength and 0.93 (scaled down to 93%). The value 0.93 is completely arbitrary and is likely just what the author found appealing.
Since the scale strength ranges from 1 to 0.75 and the scale factor is never smaller than 0.93, the scale factor only changes for the first third of the xDistance. All scale strength values in the next two thirds will be smaller than 0.93 and thus won't change the scale factor.
With the scaleFactor and rotationAngle calculated as above, the view is first rotated (by that angle) and then scaled down (by that scale factor).
Summary
So, in short. As the view is dragged to the right (as xDistance approaches 320 points), The view linearly rotates from 0° to 22.5° over the full drag and scales from 100% to 93% over the first third of the drag (and then stays at 93% for the remainder of the drag gesture).
The common way to create a font with GDI is to use the desired point size and the target device's vertical resolution (DPI) like this:
LOGFONT lf = {0};
lf.lfHeight = -MulDiv(point_size, GetDeviceCaps(hdc, LOGPIXELSY), 72);
...
HFONT hfont = CreateFontIndirect(&lf);
Assuming the default MM_TEXT mapping mode, this converts point_size into the pixel height for the desired device. (This is a common approximation. There are actually 72.27 points in an inch, not 72.) (The minus sign means I want to specify the actual character height, not the cell height.)
If I want to create a sideways font--that is, one with an orientation and escapement of 90 degrees--do I use LOGPIXELSX rather than LOGPIXELSY? For some of the printers I'm targeting, the horizontal and vertical resolutions are different.
Generally, if I want an angle of theta, do I combine LOGPIXELSX and LOGPIXELSY? I'm thinking of something like this:
// Given theta in degrees (e.g., theta = 45.0) ...
double theta_radians = theta * 2.0 * pi / 360.0;
int dpi = static_cast<int>(GetDeviceCaps(hdc, LOGPIXELSX) * sin(theta_radians) +
GetDeviceCaps(hdc, LOGPIXELSY) * cos(theta_radians) +
0.5);
LOGFONT lf = {0};
lf.lfHeight = -MulDiv(point_size, dpi, 72);
// Set escapement and orientation to theta in tenths of a degree.
lf.lfEscapement = lf.lfOrientation = static_cast<LONG>(theta * 10.0 + 0.5);
...
This makes intuitive sense to me, but I'm wondering if this is really how the GDI font mapper and printer drivers work.
1) There are 72 points/inch. (it used to be 72.27 but was changed.)
2) Combining LOGPIXELSX and LOGPIXELSY in the way that you do is fine, but
3) The font mapper doesn't look at escapement and orientation when mapping fonts. The LOGPIXELS values will only be used as part of the coordinate transformation.
http://msdn.microsoft.com/en-us/library/ms969909(loband).aspx
Not sure about how the "printer drivers work" because the statement could include many possible drivers and printers.
They could rasterize with square pixels, then stretch to non-square. They could transform glyph curves. They could do something else.