【发布时间】:2013-12-26 07:41:20
【问题描述】:
我创建了一个示例应用程序,当我们单击一个按钮时,会出现另一个视图(ResizingViewController)视图。 当我拖动 ResizingViewController 时,它正在正确移动,但我可以看到它后面的另一个视图。我认为它是超级视图(如图所示,但不能同时移动)。
请帮我修复它?(如果我拖动视图,那么两者都应该移动到相同的位置)
我的代码如下
- (IBAction)click_Action:(id)sender {
if (!resizingViewController) {
return;
}
//Creating Right Button, asigning a method to it.
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStylePlain target:self action:@selector(done)];
[resizingViewController.navigationItem setRightBarButtonItem:rightButton];
theNavigationController = [[UINavigationController alloc]
initWithRootViewController:resizingViewController];
[theNavigationController.navigationBar setTintColor:[UIColor blueColor]];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
theNavigationController.modalPresentationStyle
=UIModalPresentationFormSheet;
}
[self presentViewController:theNavigationController animated:YES completion:nil];
CGRect r = CGRectMake(100, 100, 300, 400);
r = [self.view convertRect:r toView:self.view];
theNavigationController.view.superview.frame = r;
//Adding gesture reconizer to resizingviewcontroller
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePanFrom:)];
[theNavigationController.view addGestureRecognizer:panGestureRecognizer];
}
-(void)handlePanFrom:(UIPanGestureRecognizer *) recognizer
{
CGPoint translation = [recognizer translationInView:recognizer.view];
//Changing Center of the the view as soon as user selects the view and drags
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
CGPoint r = CGPointMake(recognizer.view.center.x+100,
recognizer.view.center.y+100);
r = [self.view convertPoint:r toView:self.view];
recognizer.view.superview.center = r;
//Should not forget to give below code, else view goes out of bounds.
[recognizer setTranslation:CGPointZero inView:self.view];
}
【问题讨论】:
标签: ios draggable uipangesturerecognizer