Is it mostly a question of register?
Cases/Examples that you'd use 怎么 rather than 如何.
你怎么在这儿？ Why are you here? (Can be used as a joke to tease someone for showing up at the same place you did)
这支笔怎么会在这里？Why is this pen over here?
你怎么会回答这题？ How did you manage to answer this question?
他怎么可能会下厨？How is it possible that he knows how to cook?
你怎么来了？ Why did you come here? (An expression of surprise. Can be used when someone surprises you at the airport / at your birthday party / in front of your house, etc.)
你能告诉我接下来应该怎么做吗？Can you tell me what my next steps are supposed to be? (or like Can you tell me what I should do next? Can you tell me what should my next approach be?)
Cases/Examples where 如何 and 怎么 mean the same thing.
你这样叫我如何是好？What should I do if you decide to act this way?
你这样让我怎么办才好？What should I do if you decide to act this way?
你是如何解开这道数学题的？How did you solve this math problem?
你是怎么解开这道数学题？How did you solve this math problem?
你今天是怎么过来的？搭火车吗？How did you get here? By the train?
你今天是如何过来的？搭火车吗？How did you get here? By the train?
如何能够让他信任我呢？How can I make him trust me?
怎么样才能让他相信我呢？How can I make him trust me?
如何领养一只小狗？How to adopt a dog?
怎么样领养一只小狗？How to adopt a dog?
尝尝看，味道如何？Try it, how does it taste?
尝尝看，味道怎么样？Try it, how does it taste?
Cases/Examples where 如何 and 怎么 are used differently in the same context.
你觉得,她会如何背叛我？What do you think about how she will betray me?
她？她怎么可能背叛我？She? How is it possible that she will betray me?
Conclusion: 如何 can mean 怎么, but 怎么 means more than 如何.