Friday, 11 October 2019

Rotation gesture changing view frame

What i want to achieve: I am want to create copy of selected view. Think i have two UIImageView on View. I am selecting both the view and want to clone both the view.

Everything is working fine until i am not rotating the UIImageView. If am rotating the view UIImageView changing its frame.

UIView *viewClone = [[UIView alloc]initWithFrame:CGRectMake(fltLeadingMin, fltTopMin, fltCloneViewWidth, fltCloneViewHeight)];
viewClone.backgroundColor = [UIColor redColor];

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[viewClone addGestureRecognizer:panGesture];

for (UIImageView *imgView in arrSelectedViews) {
    //UIImageView *imgViewClone = (UIImageView*)[imgView snapshotViewAfterScreenUpdates:true];

    NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:imgView];
    UIImageView *imgViewClone = [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];



    imgViewClone.frame = CGRectMake(imgViewClone.frame.origin.x - viewClone.frame.origin.x, imgViewClone.frame.origin.y - viewClone.frame.origin.y, imgView.frame.size.width, imgView.frame.size.height);
    imgViewClone.backgroundColor = UIColor.blueColor;



    [viewClone addSubview:imgViewClone];
}

https://i.stack.imgur.com/Haz6B.png



from Rotation gesture changing view frame

No comments:

Post a Comment