Added support for autolayout and refactored internal code.

Just creating a pull request on our end for this.
rect here is possibly dubious.  It *usually* means the full rect of the view, but not always according to the docs.  It may be better to use self.bounds instead.