View unanswered posts | View active topics
It is currently Sun Apr 28, 2024 3:41 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
|
A bit more progress to share - I’ve started thinking about whether I should be able to change the appearance of the clock depending on the time. This seems to be a feature of some clocks on smart phones/tablets and watches. So I’ve created a new face: Click for large view - Uploaded with SkitchThe red dot is the second hand, BTW! After 6pm and before 6am (these are normal times - I’ll get round to checking the decimal hours later), it should change (I’ve not yet checked that it will do this live, but setting dummy times seems to work) to this: Click for large view - Uploaded with SkitchAt the moment, it’s just swapping the images, but I expect that I’ll need to actually switch layers on/off in the future to accommodate different sizes (for glows etc).
|
Wed Nov 26, 2014 1:13 pm |
|
|
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
|
Sun Nov 30, 2014 5:15 pm |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Interesting. I'll have to have a look if it's a reasonable time. There must be books surfacing soon on the topics of Swift and app development too - I'll be looking out for this too.
|
Sun Nov 30, 2014 8:26 pm |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Giving this a go. I've been looking up collection views, and I have one that displays when you tap on a button. The cell view has a UIView and another button in it - the idea is to get the ClockView to draw in the UIView. Not too sure quite how to do this - all the tutorials I've found about these things are assuming that you already know - they seem to involve dropping images in. I'll have to do some more reading about these things.
|
Mon Dec 01, 2014 7:12 pm |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Right - I think I’m getting there, but I’ve hit a snag - or rather a crash. My current goal is to make something based on a UICollectionView appear - even if it’s static images! I think it may be down to me not connecting outlets properly, but xCode seems not to have made the connection. Usually there’s a little filled in grey dot: So this one is good - the outlets have been connected properly. However, in my ClockSelector.swift file, the dot isn’t filled in: Now, this is odd as the connections are shown as being made in the Inspector: And I can set them up in Interface Builder: From what I have been reading, the crash I am experiencing can be down to disconnected outlets, so I am guessing that this is where the problem lies. So, if I can get those outlets to connect properly, then I should be OK. To outline what I have - I have two panels in Interface Builder: 1 - The main clock and 2 - The view controller. When you tap on a button, the second pane should pop up. It’s at this point where the crash occurs. Click for large view - Uploaded with SkitchThe crash looks like this (not seen this output before) Click for large view - Uploaded with SkitchNot sure what “Swift Dynamic Cast Fails” means yet - my next port of call on Google. The problem I have is that all the tutorials I read tell you how to set up a CollectionView as the first thing you come across - either as a gallery app type demo, or as a plain demo with nothing else. I’m trying to get a collection to display when a button is tapped.
|
Tue Dec 02, 2014 11:22 am |
|
|
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Hmm...
Well first off your segues are a little messed up. You should only ever have segues in one direction.
It's quite hard to see what's going on here.
If you're online later I can have a look with you on a Google Hangout if you want?
Might even be able to get some remote help stuff going.
Better that way than me just editing stuff I think. Then you can see what I'm doing and why.
|
Tue Dec 02, 2014 4:22 pm |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
I could give that a go - give me a shout when you're around. Ping me in FB messenger or something. I've not been well, the last few days (chest infection), so best not leave it too late. I've been trying to follow advice from various sites, which is why the segues are as they as - it was a solution suggested on StackOverflow. I'm assuming that people there know more than I do (and it seems to be the only way to return).
|
Tue Dec 02, 2014 5:00 pm |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Just to follow up from my last couple of posts - Oli and I had an interesting couple of hours on Google Hangouts last night looking at the clock app. The result of the evening was that there is a really nice looking clock selection pane which looks like this: Click for large view - Uploaded with SkitchEach of the clocks in that pane are live - they sue the same object that the main display uses, but presents them in what could be a scrollable selection. Tapping on the face of choice loads that into the main clock display. The beauty of all this is that I can define a new clock face, add it to a list and it all just happens. I’m somewhat relieved to say that I wasn’t too far from what was needed to achieve this, but it always helps to have someone more knowledgeable take a look and offer advice. Interestingly, it seems to involve a lot less code than I was led to believe by the examples I’d been looking at on line. So, thanks to Oli for that. Oh - the fourth face is me experimenting with something. I’ve just found that I can clip sub layers to the UIView (I may switch to masking, but this answers an immediate question so I’ll stick with the self.clipsToBounds = true for now), so I’m having a bit of a play with that. A couple of ideas spring to mind. It relies on me finding just the right font, though.
|
Wed Dec 03, 2014 10:26 am |
|
|
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Just to show you what can happen when people don't know what they're doing... That's a single ViewController file. In a project I may be taking on.
|
Wed Dec 03, 2014 9:08 pm |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
That's a lot of things to show!
|
Wed Dec 03, 2014 9:40 pm |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Woo - persistence! Today (and I am sure Oli will be pleased to learn this), I managed to get the app to save the clock face so that when it returns, it’s the same one as previously selected. It’s saving the index number of the configuration in the array and reading it back when the app starts. I thought this would be a useful feature to add, as well as being helpful for me when testing newly added faces. I had to re-jig a protocol so that data sent back to the delegate bit accepted not only the configuration to display, but also the index of that configuration. Also, as promised, a new clock face to enjoy. Click for large view - Uploaded with SkitchThis one is still a clock - there are three hands, but this time, two of the hands are actually discs with the numbers on. They rotate, showing the right number in the window. I have a watch like this, and it’s bloody insane to tell the time on. I thought that something similar would work nicely in this context. So that’s four faces to date, an easy way to change faces, and that state is saved so when the app is relaunched, the last chosen face is displayed. I’m dead pleased with this. I may have to try a Mac app as well (I have an idea for that - but I need to rough out specs for it - I also have a question that I’ll ask in another thread). Things to do: • I’d love to see this working on an Apple Watch now. The more I do this, the more I feel that it needs to be wrist bound as well. I expect I’ll need to do a “helper/slave” partnership, and use the phone to control what faces is displayed on the watch (I guess you’d send the necessary graphics to the watch as needed). • Also, do what Oli has suggested and dump hands into arrays, so I can have more than one second hand. In the first face, the day/night thing is actually just another hour hand, and it]s specially catered for. That hard coding needs to be removed. The configuration of everything needs to be in the configuration data, not the engine. • Chuck it on the App Store. I expect some people may want such a thing in their lives.
|
Thu Dec 04, 2014 3:58 pm |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Oli will be please - I’ve started to work on putting the hands and decorative elements into arrays. I’ve spent quite a bit of time on the hour hands today (this will be my model for the others). Hour hands are now pushed into an array - so you can have as many as you want. An array of CALayers is created to accommodate them, and ClockView now displays them all correctly. I am aware that I may be creating CALayers as I swap themes - so when I’ve done this, I’m aware that I’ll have to destroy them to stop a build up, or find a way to manage them. Quite pleased that I’ve done what I’ve done today.
|
Mon Dec 08, 2014 4:32 pm |
|
|
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Nice! Yeah, I was going to suggest scrapping all the layers and creating them again when the config changes (it won't change that often so not too worried about performance).
|
Mon Dec 08, 2014 5:46 pm |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
Done that - so all the layers are now contained in arrays (all the hour hands together, second hands, etc.) and the code now loops though those, drawing them and rotating them as needed. When you change the clock face, it scraps the layers and rebuilds them. This gets rid of the funny “dance” they did as layers are resized and moved around. It looked entertaining at first, but it got annoying. There’s a couple of niggles in the code that I need to straighten out (I expect that there is some duplication of functions going on), and possibly a question for later if I can’t resolve a problem. Edit: Starting to chip away at the code. I’m realising now that hands and decoration elements are the same - graphical objects - and as such they only become hands if I put them in a “hands” array, and they only become decorations if they go in the “decorations” array. At that point, the ClockView object knows what to do with them. The fly in the ointment is that some decorations MAY be animated (ie they may be visible cogs rotating in the background, for example), and they need to be handled differently to hands. So I’m having a bit of a think about this - but I may be stripping more code out as things start to sink in a little more. A lot has gone (or been commented out) today as I’ve worked through putting things in arrays. More will go, I expect, as I work through this. After that, the question which I won’t ask yet because it will probably distract me. Right now, though, everything is now in an array depending on its function.
|
Tue Dec 09, 2014 10:46 am |
|
|
paulzolo
What's a life?
Joined: Thu Apr 23, 2009 6:27 pm Posts: 12251
|
A bit of fun. I’ve set it up now so that decoration layers rotate - they just spin dumbly. There are start and end angles, as well as a duration. The result is (for now) that I can have gigs in the background seemingly “working” the mechanism. Eventually, I’ll add in oscillation, so some elements move back and forth, a bit like a pendulum would. For now, though, this hideous image shows what I have: Click for large view - Uploaded with SkitchOuter cog rotates clockwise once every 30 seconds, the inner one rotates anticlockwise every 20 seconds. I’m rather pleased with this, and because I spent some time lumping elements into arrays, I’ve had to do very little to get this working. OK, so next step is to make a clock face that has guts - that is some inner workings that are behind the face and hands. Wish me luck.
|
Thu Dec 11, 2014 9:54 am |
|
|
Who is online |
Users browsing this forum: No registered users and 103 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
|
|