こんにちは、私は iOS 開発の初心者です。ビューからツールバーにラベルをドラッグしようとしています...しかし、ラベルはツールバーの裏側に移動します.ツールバーの前にラベルをドラッグしたい..この問題に関して何か助けてください..... .これは私が今まで行ったコードです
- (void)viewDidLoad {
[super viewDidLoad];
UIToolbar *backgrdtoolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,44)];
[backgrdtoolbar setBarStyle:UIBarStyleBlackOpaque];
[self.view addSubview:backgrdtoolbar];
mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 45)];
[mainScroll setContentSize:CGSizeMake(600,45)];
[mainScroll setBackgroundColor:[UIColor clearColor]];
[mainScroll setShowsHorizontalScrollIndicator:NO];
mainToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 600, 44)];
[mainToolbar setBarStyle:UIBarStyleBlackTranslucent];
[self.view addSubview:mainScroll];
[mainScroll addSubview:mainToolbar];
UIBarButtonItem *b1 = [[UIBarButtonItem alloc]initWithTitle:@"1" style:UIBarButtonItemStyleBordered target:self action:@selector(_1:)];
UIBarButtonItem *b2 = [[UIBarButtonItem alloc]initWithTitle:@"2" style:UIBarButtonItemStyleBordered target:self action:@selector(_1:)];
UIBarButtonItem *b3 = [[UIBarButtonItem alloc]initWithTitle:@"3" style:UIBarButtonItemStyleBordered target:self action:@selector(_1:)];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:b1,spacer,b2,spacer,b3, spacer,b4,spacer,b5,spacer,b6,spacer,b7,spacer,b8,spacer,b9,spacer,b10,nil];
[mainToolbar setItems:arr];
}
- (IBAction)handle:(UIPanGestureRecognizer *)gesture {
static CGRect originalFrame;
if (gesture.state == UIGestureRecognizerStateBegan){
originalFrame = gesture.view.frame;
} else if (gesture.state == UIGestureRecognizerStateChanged) {
CGPoint translate = [gesture translationInView:gesture.view.superview];
CGRect newFrame = CGRectMake(fmin(gesture.view.superview.frame.size.width - originalFrame.size.width, fmax(originalFrame.origin.x + translate.x, 0.0)),
fmin(gesture.view.superview.frame.size.height - originalFrame.size.height, fmax(originalFrame.origin.y + translate.y , 0.0)),
originalFrame.size.width,
originalFrame.size.height);
gesture.view.frame = newFrame;
}
}