-2

I am trying to make a rect which is drawn using it's top right corner (x,y) instead of the usual top left. I tried scaling by -1, but that didn't do the work.

I need it because I am developing an app for RTL locale.

Paebbels
  • 15,573
  • 13
  • 70
  • 139
Daniel Rahamim
  • 285
  • 2
  • 18
  • 1
    Your question is quite vague, try to explain better what you're trying to achieve or post some of your code – Eilon Aug 01 '16 at 18:06
  • Well, currently every rect is drawn from the top left corner to the left. I want same effect only drawing the rect from it's top right corner to the left. – Daniel Rahamim Aug 01 '16 at 18:08
  • If I understood it correctly, it isn't possible in `UIKit`. But there sure are workarounds, post what you actually need to achieve and we could help you. – Eilon Aug 01 '16 at 18:18
  • I have a curtain which covers half of the screen, from the middle to end of the screen width. Now, I want to animate it out by making it's width to 0 – Daniel Rahamim Aug 01 '16 at 18:33
  • You can alternatively, in addition to animating the width, also animate the `origin.x` of the frame to be the maximum `x` of the frame before the animation. Let me know if should post an answer with the code. – Eilon Aug 01 '16 at 18:52
  • Thanks, thats exactly what I was doing, but when I am rotating the device, the right curtain (I also have left curtain) is stuck at the middle of screen, instead of being at the right edge, like the left curtain keeps at the left edge. – Daniel Rahamim Aug 02 '16 at 05:10
  • If you use constraints (or auto-resizing masks), the curtain will move as the device is rotated. – Rob Aug 02 '16 at 05:24
  • @Rob, yes thats what I was missing! – Daniel Rahamim Aug 02 '16 at 05:39

1 Answers1

0

If you use auto layout, you can use the leading and trailing constraints (rather than left and right constraints) and the animation will automatically be adjusted for the target language. For example, consider the following simplistic demo that overlays a "curtain" view, and then, two seconds later "pulls it aside" by animating the trailing constraint:

let curtain = UIView()
curtain.backgroundColor = .darkGrayColor()
curtain.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(curtain)

let trailingConstraint = curtain.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor)

NSLayoutConstraint.activateConstraints([
    curtain.leadingAnchor.constraintEqualToAnchor(view.leadingAnchor),
    curtain.topAnchor.constraintEqualToAnchor(view.topAnchor),
    curtain.bottomAnchor.constraintEqualToAnchor(view.bottomAnchor),
    trailingConstraint
])

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
    trailingConstraint.constant = -self.view.bounds.size.width
    UIView.animateWithDuration(0.5) {
        self.view.layoutIfNeeded()
    }
}

If your project's localization is a LTR language, it will animate the pulling back of this "curtain" from the right edge.

But if you project's localization is a RTL language, such as shown below, then it will animate the pulling of this "curtain" from the left edge:

enter image description here

Rob
  • 415,655
  • 72
  • 787
  • 1,044