2014-01-06 1 views

ответ

20
// Method for generating a path 
UIBezierPath *myPath = [self generateAPathInBounds:boundingRect]; 

// Create two transforms, one to mirror across the x axis, and one to 
// to translate the resulting path back into the desired boundingRect 
CGAffineTransform mirrorOverXOrigin = CGAffineTransformMakeScale(-1.0f, 1.0f); 
CGAffineTransform translate = CGAffineTransformMakeTranslation(boundingRect.width, 0); 

// Apply these transforms to the path 
[myPath applyTransform:mirrorOverXOrigin]; 
[myPath applyTransform:translate]; 
-1

Это правильный ответ:

// Method for generating a path 
UIBezierPath *myPath = [self generateAPathInBounds:boundingRect]; 

// Create two transforms, one to mirror across the x axis, and one to 
// to translate the resulting path back into the desired boundingRect 
CGAffineTransform mirrorOverXOrigin = CGAffineTransformMakeScale(-1.0f, 1.0f); 
CGAffineTransform translate = CGAffineTransformMakeTranslation(CGRectGetMidX(boundingRect), 0); 
CGAffineTransform translateBack = CGAffineTransformMakeTranslation(-CGRectGetMidX(boundingRect), 0); 

// Apply these transforms to the path 
[myPath applyTransform:translate]; 
[myPath applyTransform:mirrorOverXOrigin]; 
[myPath applyTransform:translateBack]; 
+0

Что такое «правда» об этом - это, кажется, скопировать, вставленный из другого ответа с добавлением, что не имеет никакого объяснения? – Mike

+0

@Mike мой ответ содержит 3 необходимые преобразования – k06a

+0

Почему третий нужен? Вы скопировали код в принятом ответе и добавили код без изменения комментария, поэтому нет объяснений. – Mike

1

Следует отметить, что вам может понадобиться дополнительный код в зависимости от того, где в общей точки зрения путь, который вы пытаетесь зеркала.

Если вы пытаетесь зеркально отразить путь, который занимает весь вид (или по крайней мере совпадает с координатой 0 оси, на которую вы зеркалируете), тогда ответ @ wbarksdale будет работать для вас. Однако, если вы пытаетесь зеркально отобразить путь, который представляет собой небольшую часть общего вида, которая находится где-то посередине представления, вам нужно сделать больше работы. В общем, алгоритм, как этот

//this rect should be the bounds of your path within its superviews 
    //coordinate system 
    let rect = myPath.bounds 
    //first, you need to move the view all the way to the left 
    //because otherwise, if you mirror it in its current position, 
    //the view will be thrown way off screen to the left 
    path.apply(CGAffineTransform(translationX: -rect.origin.x, y: 0)) 
    //then you mirror it 
    path.apply(CGAffineTransform(scaleX: -1, y: 1)) 
    //then, after its mirrored, move it back to its original position 
    path.apply(CGAffineTransform(translationX: rect.origin.x + rect.width, y: 0)) 

В общем, алгоритм должен быть

  1. Переместить путь либо к самой левой или самом верху зрения в зависимости от того, являются ли вы листать по горизонтали или по вертикали, используя CGAffineTransform(translateX....)

  2. Зеркало вид при помощи CGAffineTransform(scaleX....

  3. Переместите вид в исходное положение с помощью CGAffineTransform(translateX....)