View unanswered posts | View active topics
It is currently Sun May 04, 2025 7:44 am
Dipping the toe in - Swift, Xcode, adaptive layouts
Author |
Message |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Someone on Twitter has just asked me if it's for sale on the App Store.
|
Wed Nov 19, 2014 11:48 am |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|

Another question - thought I’d ask before I completely disrupt what I have. I may want to change the look of the clock. I get that this is easy -I have a pile of CA Layers, and all I need to do is change the images, as well as the centre of rotation. So (and this is pseudocode), I have this: currently in ClockView.swift : What I think I should be doing (just so I can separate the design/layout of the clock) is this: in clockView.swift : and then in clockface1.swift: My reasoning being that each clockface#.swift file will effectively draw and layout each design of face, but will not be involved in the running of the clock. I was thinking of using separate files just to keep things easy for me to follow, and this should allow the user to select a clock face and when they do, the appropriate function would be called, revising the clock. However, would variables like the CALayer secondHandLayer be visible to functions elsewhere in the app? This is a bit of forward thinking on my part. I’d like to include an option for the user to change the clock face, so I need to prepare for that by separating the style from the mechanism.
|
Wed Nov 19, 2014 12:48 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Hmm... yeah, you definitely want to separate the "look" from the "logic". However, what I think might be better is to have something like a "Configuration" class. I'm just typing off the top of my head atm so I haven't thought it through fully. Create a class with properties like... Now in your actual clockView you can give it a property like... And when you "draw" your clock and create the layers etc you can do... So now you can create instances of your Config class to create different "looks" for the clock. This way you only have one ClockView class and you can make it look different by using different instances of a single ClockConfig class.
|
Wed Nov 19, 2014 5:13 pm |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Hmm - I'll have to think about that. Possibly some experimentation tomorrow. And Googling. Lots of Googling, I expect.
|
Wed Nov 19, 2014 6:03 pm |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Ok - so my approach just isn’t going to work (damn). This is doe to the fact that Swift doesn’t like this kind of mucking about: code fragments in ClockView.swift: in ViewController.swift: So, I found that you nseed to set up protocols because variables can’t be accessed in this way otherwise. Like this. In Configuration.swift: and in ViewColtroller (in ViewDidLoad - but I expect AwakeFromNib should be used): This compiles and appears to return an image reference, so it appears to work. I’ll have to think about how I move this on, as it seems rather odd. I’m not sure I fully understand Oli’s method for setting the config property, or how I’d change the look of the clock “mid flight”. I have some ideas, but I need to try them out.
|
Thu Nov 20, 2014 10:27 am |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|

I really shoudl be doing somehting else. I’ve chased this round a few times, and not got any further. Here’s the problem. 1 - I have a Configuration.swift file that looks like this: In ClockView.swift I have this: protocol ClockViewClass { func drawFace(configuration: config) } And in ViewController.swift I have this: The problem is this: when ItsMyClock.drawface( clockface1 ) is called, nothing happens. I am expecting the clock face to change to a new one. I expect that is because I am creating a new instance of ClockView and that’s the problem. However, if I do this: I get a compiler error: 'config' is not convertible to 'ClockView' What I am trying to do is pass the configuration to the drawFace method in ClockView. If I do this: with drawFace defined like this: I get the following compiler error: Missing argument for parameter #1 in call I expect I’ve got this arseaboutface. I expect you can see what I’m trying to do. Really, I’m just trying to call drawFace() in ClockView. I’m using protocols because that seems to be the way to get access to variables etc. within Classes.
|
Thu Nov 20, 2014 2:00 pm |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Damn - I feel I’m really close, but things still bug me. ClockView is now doing this to set up the variables (I was getting errors I could not get around when trying to use init() ): This works - when I call ClockView.drawFace( somevariable ) the println is called. Hooray! Noting here that it’s called in VideDidLoad() in View.Controller, and it runs after ClockView’s AwakeFromNib() so all the variables SHOULD be in place. However, if I change drawFace to: I get the error "ClockView.type does not have a member named 'faceLayer'" which confuses me, as I’ve set it up previously. Same if I remove the “self”.
|
Thu Nov 20, 2014 4:23 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
It's hard to tell without seeing it. Would it be possible to share the project or put something on gist so I can have a look?
|
Thu Nov 20, 2014 11:48 pm |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Thanks. I’ll DM you with a DropBox URL.
|
Fri Nov 21, 2014 9:44 am |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Oliver’s helped me with my clock face problem, and given me more things to think about as a result. One of them was to do with the aspect ratio of hands passing between the various configuration settings. It seems that I was heading in the right direction, with my inexperience to help me. Anyway, as evidence of my success, I’ll post the draft of the second clock face running in the simulator. Click for large view - Uploaded with SkitchIt needs some tidying up (esp some of the numbers), but you get the idea. It’s actually based on a clock I own, which was very likely from Woolworths - my mum says she remembers them. So it’s a regular guy’s art deco clock, not a posh one. Thanks, Oliver! 
|
Sat Nov 22, 2014 11:52 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Awesome! Looking good now  It's made me think about how I would approach other similar apps. Very cool though. 
|
Sun Nov 23, 2014 1:50 am |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Today’s progress: • Positioning hands (no longer confined to the middle of the dial) • Can now toggle between dial 1 and dial 2 - noting that when I add dial 3, I should be able to up the count limit and it should just work™
|
Sun Nov 23, 2014 6:37 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Awesome  how did you do the positioning? Also, yeah, you should be able to create an array of configurations to switch between. Also, something to blow your mind. You can now do things like put the clockView into a collection view or table so the user can pick from the configurations by seeing them in action 
|
Sun Nov 23, 2014 9:43 pm |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
In a nutshell - added a CGPoint to the Configuration, and in ClockView amended your positioning code so that it doesn’t centre any more. I also created a modifier variable which scales the numbers down (or up) assuming that 768 is the native size. I am working all my clock faces in a 768x768 document, so I can get the dimensions form that. I plug those numbers in, and the app does the scaling for me. I was considering something along those lines. I need another clock face so I can test against three. Hmm - I was wondering how I could present a selection matrix. Right now, you tap the button, and it hop from one to the next, and back to the beginning again. I’d like some kind of selection tool where you pan/scroll between them and tap the one you want. I guess you’d throw an instance of ClockView in each cell/pane, and tell it which one to show. Something to ponder over.
|
Sun Nov 23, 2014 11:01 pm |
|
 |
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Oh - as an aside, my wife still doesn’t get WHY I’m doing this. Who, she asks, would actually WANT a Metric Clock? I told her that someone asked me if it was available to buy on the app store. She said that “that’s one person”.  I don’t think she fully understands this. I’ll remind her of this when she shows me the chicken she’s animating in Toon Boom Studio. She does like the square clock, though.
|
Sun Nov 23, 2014 11:04 pm |
|
|
Who is online |
Users browsing this forum: No registered users and 7 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum
|
|