UIViewController offsets scrollview subviews

September 22, 2014 Leave a comment

I was just wondering why my Scrollview Content would always beoffset to what i set it up in Storyboard (Xcode). I use a UIViewController and changed it’s view’s class to UIScrollView.

The layout of my scrollview in Xcode Storyboard

The layout of my scrollview in Xcode Storyboard

The problem was, that all the content which i played out in Xcode was offset by the height of the toolbar during runtime. This did not happen when the view was of class UIView, as by default. I therefore tried to set the subviews frames during runtime but this seems to be restricted by the loaded nibs somehow.

Subviews have a offset in y direction with a height of the toolbar

Subviews have a offset in y direction with a height of the toolbar

for(UIView* subview in self.view.subviews){ [subview setFrame:CGRectOffset(subview.frame, 0, -[self navigationController].toolbar.frame.size.height)];}

I finally found the reason for my problem in the attributes inspector of my ViewController.

Turn "Adjust Scrollview Insets off"

Turn “Adjust Scrollview Insets off”

The Option “Adjust Scroll View Insets” must be disabled for this purpose. It’s probably something which tries to prevent the offset from being hidden by the toolbar. But using the layout in interface builder to manage your subviews obviously interferes with this option. You should therefore turn it off!

offset removed by turning off "Adjust Scrollview Insets"

offset removed by turning off “Adjust Scrollview Insets”



HSV RGB IKEA lamp + IR Remote

November 12, 2013 2 comments

My first Awesome IKEA lamp had multiple trimmers and push buttons to setup speed, brightness and color. I now added a remote control to get rid of all these. I chose one of these common rgb remote controls that are shipped with every other cheap rgb lamp. I got it from dx.com. The led i use is a 3W rgb star led from ebay with the following specifications:

Red=2,4V, Green=3,4V, Blue=3,4V, 350mA per channel

Make sure you do not get one with common “+”; if so you can’t use p mosfets but must use the n version instead. Common ground is no problem. You’ll get a complete partlist from the eagle file. The main changes from the original layout are:

  • IR_REMOTE: CR2025


I uploaded everything including the schematic, board and the code: Download!

The code is neither commented nor nice. Feel free to improve it 😉 There is a little problem with this version; the p-mosfets seem to have great leakage current so the leds wont turn off completely. I think the PORTD has to little output power…

Categories: Uncategorized

Awesome HSV RGB IKEA lamp

June 30, 2012 6 comments

When my girlfriend gave me her birthday present, i was overwhelmed. The drawing was perfect, I loved the motive, details and shadows. And it came that she had her own birthday! This was the moment i decided not to buy one of her wishlist’s entrys (yes i keep track) but build something by my own too (let’s just stick to buying things okay?). I thought about painting a picture too but decided against it. I just didn’t want to reveal my inner artist and make her jealous.

Since im a student of it and electronics, i chose to build something wired.  It had to be cool but also instructive for me i though. I always planned on building a “proper” RedGreenBlue LED Lamp which could fade between colors. But i never found the time nor the motivation to do something símilar in my freetime. The first attempts on my Arduino Board were pretty basic. The colors were fading, yes, but randomly which means (in RGB color space) pretty white changes to a white reddish to bright white reddish to a bright white reddish with a touch of green or blue. This wasn’t  that exciting at all. I “went” to the mikrocontroller.net community and asked about color spaces. My idea was to make a distinction between color and brightness and avoid same colors with just different portions of white. I found that the hsv (hue saturation value) color space met my needs. It allowed me to use a simple potentiometer for choosing the color (hue) and a further one for the brightness, while the saturation remains constant (no white parts please ;-))

I started coding (checkout github) the code for an atmega8 controller and tested it on a breadboard first. I found and bought a perfect fitting aluminium globe at IKEA which could hold both the led and the electronic circuit. Then I began with the final board layout in Eagle and ordered the other parts at reichelt: Three Potentiometers (two logarithmic ones), three nmos transistors, resistors, capacitors, push buttons, toggle and finally the power supply (5V2A).

I attached the parts to the new board and tested it with Georg who provided an oscillocope and even a 3D printer. I  designed and printed two plastic parts for the globe to hold the led and the board.

Also I changed the original design from a standing lamp to a laying one. I though it would look nicer and lighten a wall much better. Also the potentiometers and buttons were better accessible (It’s not a bug it’s a feature).

Everything looked fine but a random flashing which disturbed me. One user from the forum gave me hint that there could be something wrong with my code since he had the same problem in the past. So glad this guy read the post -> no flickering anymore!

During the project i learned a lot about the whole progress of implementing a vision. I really started with a vague idea and then made use of a great toolchain (3d printing, uC development, board layout in eagle, testing testing and testing with oscilloscope)… Also i must say that there were a lot of coincidences like a broken diode and a wrongly connected mosfet which i eventually hadn’t noticed in other places… Maybe you (Kenzie) remember that i was happy about the one day on skype? Yeah, i figured the board was actually working … so this was my last week; for you! be happy!

Looking forward to party in fading colors!


https://github.com/kreuzUndQwertz/hsv2rgb (code and board layouts as well as the openscad 3d designs)

http://www.mikrocontroller.net/topic/262143#postform (thread on rgb space and flashing issue)

Categories: electronics, Uncategorized

Ratelet a OSX Menulet to control iTunes’ rating and volume

May 23, 2012 Leave a comment

Hey, i finally submitted my first official App to the Apple App Store! Check it out 😉

Ratelet is shown in your statusbar and gives you easy access to the rating of the current song and iTunes volume.

Ratelet will automatically hide itself from the statusbar when iTunes is not running and reveal if iTunes starts. You can hide the volume slider if you only need the rating bar.

Quickly changing iTunes volume can be useful especially when you use Airplay or output sound digital because the Mac’s volume buttons only affect analog output volume!





Anchor Point vs. Position (CALayer)

April 3, 2012 1 comment

Yesterday i was trying to do some animation which included rotation along the x axis. For this i needed to figure out how to set the anchor point of my layer without moving it in the superlayers coordinate system. But when i setted a different anchor Point the layer moved.
I didn’t know why and some internet resources did not help me at all.

I noticed that both setting the position or the anchor point would move the layer. But setting the one does not affect the other. Some pages on the web explained this bahvior with examples. Now i will give you an example too but no instrutions or advices for how to work with it in concrete cases. This post tries to explain the concept in general.

The anchor point is an attribute of every layer. Its coordinates describe a realtive position in your layer. Every point from 0.0/0.0 to 1.0/1.0 describes a point withing the bounds of the layer. Every negative pair like -1.0/-1.0 is placed once the height to the top and once the width to the left oustide the layers bounds. For instance 0.5/0.5 is the center of a layers bounds. Make sure you understand that this point is independent from the layers or superlayers actual dimension (in pixels or whatever). 0.5/0.5 always is the center independent from if its a layer of size 500×500 or 500×150.

Position on the other hand is expressed in actual layer dimensions but referrs to the superlayer not the layer itself! Position in short says “Position the layer in a way that the anchor point of the layer matches the position in my superlayer”.

Example: You have created a view (50×50) and added it to the center of your superview (150×150) using setCenter…
The anchor point of every layer is always set to 0.5/0.5 at creation time and therefor points to the center of the layer. Now when you added your view and placed it to the center, the position attribute of the layer makes shure that the layer is centered in respect to your anchor point (currently 0.5/0.5).

Since the anchor point is the center of the sublayer, the position attribute must be the center of the super layer so that the layers center is the superlayers center. As stated above, the position attribute now says “the layer is positioned in a way that the relative point 0.5/0.5 (anchor point) is at the super views center by setting the position to 75×75 sublayer.


Now imagine you change the anchor point so that not the layers center is centered in the superlayer but the upperleft corner. All you need to do is setting the anchor point to 0.0/0.0 which represents the realtive position for the upper left corner.

NSStatusItem highlight custom Button workaround!

March 30, 2012 Leave a comment

I’m building a Menulet with multiple buttons. Since these buttons do no inherit the default behavior of getting blue when clicked, i searched for a quick solution. Since i don’t know how to implement a custom cell and had no ambition to do so, i finally found a nice and quick solution.

The following lines make shure the button won’t show a white background which is default for every buttonType but NSMomentaryChangeButton.

  1. //make sure button won’t show the “alternateImage” when selected
  2. [configureItem setButtonType:NSMomentaryChangeButton];
  3. [configureItem setBezelStyle:NSRegularSquareBezelStyle];
  4. [configureItem setBordered:NO];

Then the next few lines are called in the MenuItem’s delegate every time the menu will open or close.

  1. #pragma mark menu delegate
  2. (void)menuWillOpen:(NSMenu *)menu {
  3.         [[configureItem cell] setBackgroundColor:[NSColor selectedMenuItemColor]];
  4. }
  5. (void)menuDidClose:(NSMenu *)menu {
  6.         [[configureItem cell] setBackgroundColor:[NSColor clearColor]];
  7.     [menu release];
  8. }

Menulet for iTunes volume

January 30, 2012 Leave a comment

Menulet to control iTunes volume

Just needed a quick access to control uatunes volume since this also applies to the airplay volume. Here’s a small Menulet which offers a slider to control it. Have fun 😉


I used the ScriptingBridge and this article to build the app!