Используйте одиночный replace
с функцией замены, чтобы все замены происходили одновременно, чтобы гарантировать, что только что замененный символ не будет заменен снова:
const input = "R U R' U' R' F R2 U' R' U' R U R' F";
const replaceObj = {
R: 'F',
F: 'R'
}
const output = input.replace(/[RF]/g, char => replaceObj[char]);
console.log(output);
Ваше представление все еще прозрачно, но как только Ваш модальный контроллер наверху стека, представление позади него скрыто (как имеет место с любым самым верхним контроллером представления). Решение состоит в том, чтобы вручную анимировать представление самостоятельно; тогда позади - viewController не будет скрыт (так как Вы не будете 'оставлять' его).
Для тех, кто хочет увидеть какой-то код, вот что я добавил в свой контроллер прозрачного представления:
// Add this view to superview, and slide it in from the bottom
- (void)presentWithSuperview:(UIView *)superview {
// Set initial location at bottom of superview
CGRect frame = self.view.frame;
frame.origin = CGPointMake(0.0, superview.bounds.size.height);
self.view.frame = frame;
[superview addSubview:self.view];
// Animate to new location
[UIView beginAnimations:@"presentWithSuperview" context:nil];
frame.origin = CGPointZero;
self.view.frame = frame;
[UIView commitAnimations];
}
// Method called when removeFromSuperviewWithAnimation's animation completes
- (void)animationDidStop:(NSString *)animationID
finished:(NSNumber *)finished
context:(void *)context {
if ([animationID isEqualToString:@"removeFromSuperviewWithAnimation"]) {
[self.view removeFromSuperview];
}
}
// Slide this view to bottom of superview, then remove from superview
- (void)removeFromSuperviewWithAnimation {
[UIView beginAnimations:@"removeFromSuperviewWithAnimation" context:nil];
// Set delegate and selector to remove from superview when animation completes
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
// Move this view to bottom of superview
CGRect frame = self.view.frame;
frame.origin = CGPointMake(0.0, self.view.superview.bounds.size.height);
self.view.frame = frame;
[UIView commitAnimations];
}